Python Practice › Pandas Programs › Program 67

Reverse row order

EasyPandas Programs · 67 of 95

Write a pandas program to reverse the order of rows.

Advertisement
Output
    name  age
2  Peter   29
1   John   27
0   Alex   30

Approach

  1. iloc[::-1].

Solution

Python
import pandas as pddf = pd.DataFrame({"name": ["Alex", "John", "Peter"], "age": [30, 27, 29]})print(df.iloc[::-1])
Output
    name  age
2  Peter   29
1   John   27
0   Alex   30
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More pandas programs

← All 95 Pandas Programs