To sort a dataFrame in Python Pandas by two or more columns, we call sort_values
with the ascending
argument.
For instance, we write
df.sort_values(['a', 'b'], ascending=[True, False])
to call sort_values
on the df
data frame with an array of columns to sort as the first argument.
And we set ascending
to an array of booleans to sort the columns in the order listed for each column.