在列中找到最大值的3行的最有效方法?
让我们说有一个dataframe df
Name Balance
A 1000
B 5000
C 3000
D 6000
E 2000
F 5000
我正在寻找一种方法,通过这种方法,我可以在所有方面获得最高余额的三行。
df['balance'].get_indices_max(n=3) # where is no. of results required
输出这些索引将用于获取行何时:
D 6000
F 5000
B 5000
更新:有关可接受的答案的额外说明
可能的“保持”值 -
first : prioritize the first occurrence(s)
last : prioritize the last occurrence(s)
all : do not drop any duplicates, even it means selecting more than n items.
Lets us say there is a dataframe df
Name Balance
A 1000
B 5000
C 3000
D 6000
E 2000
F 5000
I am looking for an approach through which I can get three rows with highest balances among all.
df['balance'].get_indices_max(n=3) # where is no. of results required
Output when these indices will be used to get rows:
D 6000
F 5000
B 5000
UPDATE : EXTRA NOTES REGARDING THE ACCEPTED ANSWER
Possible "keep" values -
first : prioritize the first occurrence(s)
last : prioritize the last occurrence(s)
all : do not drop any duplicates, even it means selecting more than n items.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
回答
输出
attantion
nlargest(3,keep ='all')
示例
参考
Answer
Output
Attantion
nlargest(3, keep='all')
Example
Reference
我通常这样做
I usual do