title: Faster way to rank rows in subgroups in pandas dataframe
body: <p>I have a pandas data frame that has is composed of different subgroups.</p>
  <pre><code>df = pd.DataFrame({
  'id':[1, 2, 3, 4, 5, 6, 7, 8], 
  'group':['a', 'a', 'a', 'a', 'b', 'b', 'b', 'b'], 
  'value':[.01, .4, .2, .3, .11, .21, .4, .01]
  })
  </code></pre>
  <p>I want to find the rank of each id in its group with say, lower values being better.  In the example above, in group A, Id 1 would have a rank of 1, Id 2 would have a rank of 4.  In group B, Id 5 would have a rank of 2, Id 8 would have a rank of 1 and so on.</p>
  <p>Right now I assess the ranks by:</p>
  <ol>
  <li>Sorting by value.</li>
  </ol>
  <pre><code>df.sort('value', ascending = True, inplace=True)
  </code></pre>
  <ol start="2">
  <li>Create a ranker function (it assumes variables already sorted)</li>
  </ol>
  <pre><code>def ranker(df):
      df['rank'] = np.arange(len(df)) + 1
      return df
  </code></pre>
  <ol start="3">
  <li>Apply the ranker function on each group separately:</li>
  </ol>
  <pre><code>df = df.groupby(['group']).apply(ranker)
  </code></pre>
  <p>This process works but it is really slow when I run it on millions of rows of data.  Does anyone have any ideas on how to make a faster ranker function.</p>