Python Pandas - 仅显示列的 MAX 值的 DF 中的行 [英] Python Pandas - Only showing rows in DF for the MAX values of a column
问题描述
搜索了这个,但找不到答案.
假设我有一个数据框(对格式表示歉意):
戴夫 400 美元
戴夫 400 美元
戴夫 400 美元
b 弗雷德 $220
c 詹姆斯 $150
c 詹姆斯 $150
d 哈利 50 美元
我想过滤数据框,以便它只显示第三列是 MAXIMUM 值的行,有人能指出我正确的方向吗?
即它只会显示 Dave 的行
我能找到的只是显示每个单独索引(索引为 A、B、C 等)的最大值的行的方法
提前致谢
这应该有效:
<预><代码>>>>df0 钱戴夫 400戴夫 400戴夫 400b 弗雷德 220c 詹姆斯 150c 詹姆斯 150d 哈利 50>>>df[df['money'] == df['money'].max()]0 钱戴夫 400戴夫 400戴夫 400searched for this, but cannot find an answer.
Say I have a dataframe (apologies for formatting):
a Dave $400
a Dave $400
a Dave $400
b Fred $220
c James $150
c James $150
d Harry $50
And I want to filter the dataframe so it only shows the rows where the third column is the MAXIMUM value, could someone point me in the right direction?
i.e. it would only show Dave's rows
All I can find is ways of showing the rows where its the maximum value for each separate index (the indexes being A, B, C etc)
Thank you in advance
This should work:
>>> df
0 money
a Dave 400
a Dave 400
a Dave 400
b Fred 220
c James 150
c James 150
d Harry 50
>>> df[df['money'] == df['money'].max()]
0 money
a Dave 400
a Dave 400
a Dave 400
这篇关于Python Pandas - 仅显示列的 MAX 值的 DF 中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!