Python Practice › Pandas Programs › Program 68

Reverse column order

EasyPandas Programs · 68 of 95

Write a pandas program to reverse the order of columns.

Advertisement
Output
   salary  age  name
0   50000   30  Alex
1   65000   27  John

Approach

  1. df[df.columns[::-1]].

Solution

Python
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
Advertisement

Learn the concept

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

More pandas programs

← All 95 Pandas Programs