-1

How do I sort a data frame using multiple columns such that each column is sorted in different order? For example, the primary sort key is column 'A' in ascending order and secondary sort key is column 'B' in descending order.

2
  • 1
    df.sort_values(['A', 'B'], ascending=[True, False]) Commented Sep 5, 2020 at 20:51
  • Thanks, it works beautifully. Commented Sep 5, 2020 at 20:58

1 Answer 1

0

The method df.sort_values has a parameter ascending wich can be a boolean or a list of booleans.

df.sort_values(['A', 'B'], ascending=[True, False], inplace=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.