-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.

fatdragon
  • 2,211
  • 4
  • 26
  • 43

1 Answers1

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)
RichieV
  • 5,103
  • 2
  • 11
  • 24