I have a groupby statement resulting the below result. How can sort the w column descending order within that grouping?
Asked
Active
Viewed 439 times
0
Indika Rajapaksha
- 1,056
- 1
- 14
- 36
2 Answers
1
You can use groupby.apply with the sort_values
df_sp.groupby(['season','home_team']).sum('w').apply(lambda x : x['w'].sort_values(ascending=False))
0
Code -
grouped = df_sp.groupby(['season','home_team']).sum('w').reset_index()
g = grouped.sort_values('w', ascending=False)
Ref link - pandas groupby sort descending order
pls share reproducible code so that others can test, above code is not tested.
Divyank
- 811
- 2
- 10
- 26
