In this Pandas tutorial, you will learn how to sort Pandas DataFrame in Python. You can easily sort the Pandas DataFrame with the following code.
# import Pandas library import pandas as pd # create a dataframe var = pd.DataFrame({'A': [65, 20, 55, 35], 'B': [5, 10, 15, 20], 'C': [25, 30, 35, 40]}) # sort the dataframe by column A var.sort_values(by=['A'], inplace=True) # display the dataframe print(var)
Output:
A B C 1 20 10 30 3 35 20 40 2 55 15 35 0 65 5 25
Free resources to learn advanced skills: AiHints and CodeAllow