首页 > 解决方案 > 在 Python/Pandas 中显示不同的值并取最大值

问题描述

我有一个数据集 df,我想只显示最大不同值。

数据

type    power
a_b     5
a_c     6
a_c     4
a_c     4
a_b     6
a_b     9

期望的

type    power
a_b     9
a_c     6

正在做

df1 = df.unique
df2 = max(df1)

任何建议表示赞赏

标签: pythonpandasnumpy

解决方案


这是groupby

df.groupby('type', as_index=False)['power'].max()

推荐阅读