Python Practice › Pandas Programs › Program 50

Reorder columns

EasyPandas Programs · 50 of 95

Write a pandas program to change the order of columns.

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

Approach

  1. Select columns in the new order.

Solution

Python
import pandas as pddf = pd.DataFrame({"name": ["Alex", "John"], "age": [30, 27], "salary": [50000, 65000]})print(df[["salary", "name", "age"]])
Output
   salary  name  age
0   50000  Alex   30
1   65000  John   27

Learn the concept

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

More pandas programs

← All 95 Pandas Programs

Leave a Comment