Python Answers

How to sort Python Pandas dataframe from one column?

Spread the love

To sort Python Pandas dataframe from one column, we call sort_values.

For instance, we write

final_df = df.sort_values(by=['2'], ascending=False)

to call sort_values with the by argument set to ['2'] to sort by column 2.

And we set ascending to False to sort the items by column 2 in descending order.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *