TC1111
TC1111

Reputation: 89

Sorting on two columns using Pandas

I have the following dataframe (this is a sample there are many rows)

      Student ID        avg
0       205842      68.333333
1       280642      74.166667

I want to sort by decreasing average percentage grade, and, if equal the Increasing Student ID.

I have been able to sort with one parameter like below, however I'm unsure how to sort with two as I want

df_pct_scores.sort_values(by='avg', ascending=False)

Upvotes: 0

Views: 52

Answers (1)

Suman Dey
Suman Dey

Reputation: 151

Please see if this works:

df_pct_scores.sort_values(by = ['avg','ID'], ascending=[False, True])

Upvotes: 1

Related Questions