Python Practice › Pandas Programs › Program 50
Reorder columns
Write a pandas program to change the order of columns.
Output
salary name age 0 50000 Alex 30 1 65000 John 27
Approach
- Select columns in the new order.
Solution
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.