【发布时间】:2014-11-06 21:42:04
【问题描述】:
我正在尝试根据 groupby 的另一列获取具有最大值的行,我正在尝试遵循此处给出的解决方案 Python : Getting the Row which has the max value in groups using groupby,但是当您申请时它不起作用
annotations.groupby(['bookid','conceptid'], sort=False)['weight'].max()
我明白了
bookid conceptid
12345678 3942 0.137271
10673 0.172345
1002 0.125136
34567819 44407 1.370921
5111 0.104729
6160 0.114766
200 0.151629
3504 0.152793
但我只想得到权重最高的行,例如,
bookid conceptid
12345678 10673 0.172345
34567819 44407 1.370921
感谢您的帮助
【问题讨论】:
-
只是一个想法,这会给你想要的吗:
annotations.groupby(['bookid'], sort=False)['weight'].max()