title: pandas: how do I select first row in each GROUP BY group?
body: <p>Basically the same as <a href="https://stackoverflow.com/questions/3800551/select-first-row-in-each-group-by-group">Select first row in each GROUP BY group?</a> only in pandas.</p>
  
  <pre><code>df = pd.DataFrame({'A' : ['foo', 'foo', 'foo', 'foo', 'bar', 'bar', 'bar', 'bar'],
                  'B' : ['3', '1', '2', '4','2', '4', '1', '3'],
                      })
  </code></pre>
  
  <p>Sorting looks promising:</p>
  
  <pre><code>df.sort('B')
  
       A  B
  1  foo  1
  6  bar  1
  2  foo  2
  4  bar  2
  0  foo  3
  7  bar  3
  3  foo  4
  5  bar  4
  </code></pre>
  
  <p>But then first won't give the desired result... 
      df.groupby('A').first()</p>
  
  <pre><code>     B
  A     
  bar  2
  foo  3
  </code></pre>