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)

3
  • df_pct_scores.sort_values(by=['avg','ID'], ascending=False) please try this Commented Feb 8, 2020 at 3:38
  • Thanks for your input, however - aren't both of these sorting by descending? The second value 'ID' I want to be ascending Commented Feb 8, 2020 at 3:39
  • Does this answer your question? How to sort a dataFrame in python pandas by two or more columns? Commented Feb 8, 2020 at 4:00

1 Answer 1

1

Please see if this works:

df_pct_scores.sort_values(by = ['avg','ID'], ascending=[False, True])
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.