Python Practice › Pandas Programs › Program 49
Rename all columns
Write a pandas program to rename columns C1, C2, C3 to A, B, C.
Output
A B C 0 1 6 8 1 3 8 2 2 9 0 6
Approach
rename(columns={...}).
Solution
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.