擅长:python、mysql、java
<p>您可以<a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.groupby.html" rel="nofollow noreferrer">^{<cd1>}</a>列<code>a</code>并找到每个组的<a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.GroupBy.max.html" rel="nofollow noreferrer">^{<cd3>}</a>,然后<a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.merge.html" rel="nofollow noreferrer">^{<cd4>}</a>返回结果数据帧以保留匹配的行:</p>
<pre><code>df.merge(df.groupby('a').c.max())
a b c
0 x1 y1 9
1 x1 y2 9
2 x2 y5 10
3 x3 y9 8
4 x4 y10 11
5 x4 y11 11
6 x4 y12 11
</code></pre>