<p>你可以试试这个;<code>sort</code>并得到<code>last</code>值</p>
<pre><code>df.sort_values('number').groupby('yearofbirth').tail(1)
</code></pre>
<p>或者可以使用<code>reindex</code></p>
<pre><code>df.reindex(df.groupby('yearofbirth').number.idxmax())
</code></pre>
<p>演示:</p>
<pre><code>In [1]: df = pd.DataFrame({'name':list('abcaac'),
...: 'yearofbirth':[1800,1800,1801,1801,1802,1802],
...: 'number':[7,8,9,4,2,3],
...: 'sex':['F'] * 6,
...: })
In [2]: df.sort_values('number').groupby('yearofbirth').tail(1)
Out[2]:
name yearofbirth number sex
5 c 1802 3 F
1 b 1800 8 F
2 c 1801 9 F
In [3]: df.reindex(df.groupby('yearofbirth').number.idxmax())
Out[3]:
name yearofbirth number sex
number
1 b 1800 8 F
2 c 1801 9 F
5 c 1802 3 F
In [4]: df.loc[df.groupby('yearofbirth').number.idxmax()]
Out[4]:
name yearofbirth number sex
1 b 1800 8 F
2 c 1801 9 F
5 c 1802 3 F
</code></pre>