擅长:python、mysql、java
<p>尝试使用<code>groupby</code>和<code>idxmax</code>的组合:</p>
<pre><code>gb = df.groupby(["Election Yr.", "Party"]).sum()
gb.loc[gb.groupby("Election Yr.")["Votes"].idxmax()].reset_index()
>>> gb
Election Yr. Party Votes
0 2000 B 90
1 2005 B 90
</code></pre>