Sorting Data Frames in Pandas

Creating a Pandas Dataframe for Demonstration, Here, we have created a dataframe in which we will perform various sorting functions.

Python3




# importing pandas library
import pandas as pd
 
# creating and initializing a nested list
age_list = [['Afghanistan', 1952, 8425333, 'Asia'],
            ['Australia', 1957, 9712569, 'Oceania'],
            ['Brazil', 1962, 76039390, 'Americas'],
            ['China', 1957, 637408000, 'Asia'],
            ['France', 1957, 44310863, 'Europe'],
            ['India', 1952, 3.72e+08, 'Asia'],
            ['United States', 1957, 171984000, 'Americas']]
 
# creating a pandas dataframe
df = pd.DataFrame(age_list, columns=['Country', 'Year',
                                     'Population', 'Continent'])
 
df


Output

Sort Pandas DataFrame

How to Sort Pandas DataFrame?

We can perform sorting in Pandas Dataframe. This article will discuss how to sort Pandas DataFrame using various methods in Python.

Similar Reads

Sorting Data Frames in Pandas

Creating a Pandas Dataframe for Demonstration, Here, we have created a dataframe in which we will perform various sorting functions....

Sorting Pandas Data Frame

...