我有这样的数据帧:
mainid pidx pidy score
1 a b 2
1 a c 5
1 c a 7
1 c b 2
1 a e 8
2 x y 1
2 y z 3
2 z y 5
2 x w 12
2 x v 1
2 y x 6
Run Code Online (Sandbox Code Playgroud)
我想groupby on column 'pidx' ,然后sort score in descending order in each group即为每个pidx
然后select head(2)是每组的前2名.
我要找的结果是这样的:
mainid pidx pidy score
1 a e 8
1 a c …Run Code Online (Sandbox Code Playgroud)