Dears, I have dataframe with 4 columns: -club name, formacja- player position, overall- skills points, player_url- name of player
a=[['club_name','formacja','overall','player_url']]
I want to search for 2 or more greatest/highest values of each club_name & position.
I tried to create pivot table, but there I can get only the max value:
b=a.pivot(a, index='club_name',columns='formacja')#,aggfunc={'overall': [ max]})
Do you know other methods?
CodePudding user response:
To get the two largest numbers you can do:
sorted([3,4,5,2])[-2:]
It will output [4,5]
You can use it also in the pivot function:
pd.pivot_table(df, values='D', index=['A', 'B'],
columns=['C'], aggfunc=lambda x: sorted(x)[-2:])
