Categories
Python Answers

How to sort Python Pandas dataframe from one column?

Spread the love

Sometimes, we want to sort Python Pandas dataframe from one column.

In this article, we’ll look at how to sort Python Pandas dataframe from one column.

How to sort Python Pandas dataframe from one column?

To sort Python Pandas dataframe from one column, we can use the sort_values method.

For instance, we write

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

to call sort_values with the by argument set to a list of column names to sort by.

And the ascending argument is set to False since we want to sort in descending order.

Conclusion

To sort Python Pandas dataframe from one column, we can use the sort_values method.

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 *