title: Ranking order per group in Pandas
body: <p>Consider a dataframe with three columns: <code>group_ID</code>, <code>item_ID</code> and <code>value</code>. Say we have 10 <code>itemIDs</code> total.</p>
  
  <p>I need to rank each <code>item_ID</code> (1 to 10) <strong>within</strong> each <code>group_ID</code> based on <code>value</code>, and then see the mean rank (and other stats) across groups (e.g. the IDs with the <strong>highest</strong> value across groups would get ranks closer to 1). How can I do this in 
  Pandas?</p>
  
  <p><a href="https://stackoverflow.com/a/23976272/1732769">This answer</a> does something very close with <code>qcut</code>, but not exactly the same.</p>
  
  <hr>
  
  <p>A data example would look like:</p>
  
  <pre><code>      group_ID   item_ID  value
  0   0S00A1HZEy        AB     10
  1   0S00A1HZEy        AY      4
  2   0S00A1HZEy        AC     35
  3   0S03jpFRaC        AY     90
  4   0S03jpFRaC        A5      3
  5   0S03jpFRaC        A3     10
  6   0S03jpFRaC        A2      8
  7   0S03jpFRaC        A4      9
  8   0S03jpFRaC        A6      2
  9   0S03jpFRaC        AX      0
  </code></pre>
  
  <p>which would result in:</p>
  
  <pre><code>      group_ID   item_ID   rank
  0   0S00A1HZEy        AB      2
  1   0S00A1HZEy        AY      3
  2   0S00A1HZEy        AC      1
  3   0S03jpFRaC        AY      1
  4   0S03jpFRaC        A5      5
  5   0S03jpFRaC        A3      2
  6   0S03jpFRaC        A2      4
  7   0S03jpFRaC        A4      3
  8   0S03jpFRaC        A6      6
  9   0S03jpFRaC        AX      7
  </code></pre>