Python Practice › Pandas Programs › Program 56

Rename one column

EasyPandas Programs · 56 of 95

Write a pandas program to rename one column.

Advertisement
Output
   Sr.no  name
0      1  Alex
1      2  John

Approach

  1. rename(columns={"old": "new"}).

Solution

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

Learn the concept

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

More pandas programs

← All 95 Pandas Programs