Python Practice › Pandas Programs › Program 49

Rename all columns

EasyPandas Programs · 49 of 95

Write a pandas program to rename columns C1, C2, C3 to A, B, C.

Advertisement
Output
   A  B  C
0  1  6  8
1  3  8  2
2  9  0  6

Approach

  1. rename(columns={...}).

Solution

Python
import pandas as pddf = pd.DataFrame({"C1": [1, 3, 9], "C2": [6, 8, 0], "C3": [8, 2, 6]})print(df.rename(columns={"C1": "A", "C2": "B", "C3": "C"}))
Output
   A  B  C
0  1  6  8
1  3  8  2
2  9  0  6

Learn the concept

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

More pandas programs

← All 95 Pandas Programs

Leave a Comment