0

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)

TC1111
  • 89
  • 8
  • `df_pct_scores.sort_values(by=['avg','ID'], ascending=False)` please try this – Talha Anwar Feb 08 '20 at 03:38
  • Thanks for your input, however - aren't both of these sorting by descending? The second value 'ID' I want to be ascending – TC1111 Feb 08 '20 at 03:39
  • Does this answer your question? [How to sort a dataFrame in python pandas by two or more columns?](https://stackoverflow.com/questions/17141558/how-to-sort-a-dataframe-in-python-pandas-by-two-or-more-columns) – Zoie Feb 08 '20 at 04:00

1 Answers1

1

Please see if this works:

df_pct_scores.sort_values(by = ['avg','ID'], ascending=[False, True])
Lucas Damian
  • 178
  • 1
  • 2
  • 11
Suman Dey
  • 131
  • 6