title: Pandas: group by index value, then calculate quantile?
body: <p>I have a DataFrame indexed on the <code>month</code> column (set using <code>df = df.set_index('month')</code>, in case that's relevant): </p>
  
  <pre><code>             org_code  ratio_cost   
  month
  2010-08-01   1847      8.685939     
  2010-08-01   1848      7.883951     
  2010-08-01   1849      6.798465     
  2010-08-01   1850      7.352603     
  2010-09-01   1847      8.778501     
  </code></pre>
  
  <p>I want to add a new column called <code>quantile</code>, which will assign a quantile value to each row, based on the value of its <code>ratio_cost</code> for that month. </p>
  
  <p>So the example above might look like this:</p>
  
  <pre><code>             org_code  ratio_cost   quantile
  month
  2010-08-01   1847      8.685939     100 
  2010-08-01   1848      7.883951     66.6 
  2010-08-01   1849      6.798465     0  
  2010-08-01   1850      7.352603     33.3
  2010-09-01   1847      8.778501     100
  </code></pre>
  
  <p>How can I do this? I've tried this:</p>
  
  <pre><code>df['quantile'] = df.groupby('month')['ratio_cost'].rank(pct=True)
  </code></pre>
  
  <p>But I get <code>KeyError: 'month'</code>. </p>
  
  <p><strong>UPDATE</strong>: I can reproduce the bug. </p>
  
  <p>Here is my CSV file: <a href="http://pastebin.com/raw/6xbjvEL0" rel="noreferrer">http://pastebin.com/raw/6xbjvEL0</a></p>
  
  <p>And here is the code to reproduce the error:</p>
  
  <pre><code>df = pd.read_csv('temp.csv')
  df.month = pd.to_datetime(df.month, unit='s')
  df = df.set_index('month')
  df['percentile'] = df.groupby(df.index)['ratio_cost'].rank(pct=True)
  print df['percentile']
  </code></pre>
  
  <p>I'm using Pandas 0.17.1 on OSX. </p>