Menu Close

How to sort Python Pandas dataframe from one column?

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.

Posted in Python, Python Answers