title: Enumerate each row for each group in a DataFrame
body: <p>In pandas, how can I add a new column which enumerates rows based on a given grouping?</p>
  <p>For instance, assume the following DataFrame:</p>
  <pre class="lang-py prettyprint-override"><code>import pandas as pd
  import numpy as np
  
  a_list = ['A', 'B', 'C', 'A', 'A', 'C', 'B', 'B', 'A', 'C']
  df = pd.DataFrame({'col_a': a_list, 'col_b': range(10)})
  df
  </code></pre>
  <pre class="lang-none prettyprint-override"><code>  col_a  col_b
  0     A      0
  1     B      1
  2     C      2
  3     A      3
  4     A      4
  5     C      5
  6     B      6
  7     B      7
  8     A      8
  9     C      9
  </code></pre>
  <p>I'd like to add a <code>col_c</code> that gives me the Nth row of the &quot;group&quot; based on a grouping of <code>col_a</code> and sorting of <code>col_b</code>.</p>
  <p>Desired output:</p>
  <pre class="lang-none prettyprint-override"><code>  col_a  col_b  col_c
  0     A      0      1
  3     A      3      2
  4     A      4      3
  8     A      8      4
  1     B      1      1
  6     B      6      2
  7     B      7      3
  2     C      2      1
  5     C      5      2
  9     C      9      3
  </code></pre>
  <p>I'm struggling to get to <code>col_c</code>.  You can get to the proper grouping and sorting with <code>.sort_index(by=['col_a', 'col_b'])</code>, it's now a matter of getting to that new column and labeling each row.</p>