Python Practice › Pandas Programs › Program 68
Reverse column order
Write a pandas program to reverse the order of columns.
Output
salary age name 0 50000 30 Alex 1 65000 27 John
Approach
df[df.columns[::-1]].
Solution
import pandas as pddf = pd.DataFrame({"name": ["Alex", "John"], "age": [30, 27], "salary": [50000, 65000]})print(df[df.columns[::-1]])Output
salary age name 0 50000 30 Alex 1 65000 27 John
Learn the concept
New to this topic? Read the lesson, then come back.