Python Practice › Pandas Programs › Program 56
Rename one column
Write a pandas program to rename one column.
Output
Sr.no name 0 1 Alex 1 2 John
Approach
rename(columns={"old": "new"}).
Solution
import pandas as pddf = pd.DataFrame({"Rank": [1, 2], "name": ["Alex", "John"]})print(df.rename(columns={"Rank": "Sr.no"}))Output
Sr.no name 0 1 Alex 1 2 John
Learn the concept
New to this topic? Read the lesson, then come back.