Python Practice › Pandas Programs › Program 67
Reverse row order
Write a pandas program to reverse the order of rows.
Output
name age 2 Peter 29 1 John 27 0 Alex 30
Approach
iloc[::-1].
Solution
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
Learn the concept
New to this topic? Read the lesson, then come back.