Renaming
rename changes column or index labels.
Example
df = pd.DataFrame({"name": ["Ada", "Kofi", "Amina", "Tunde"], "country": ["NG", "GH", "NG", "NG"], "score": [92, 78, 85, 71]})
print(df.rename(columns={"score": "points"}).columns.tolist())
df.columns = [c.upper() for c in df.columns]
print(df.columns.tolist())Result
['name', 'country', 'points'] ['NAME', 'COUNTRY', 'SCORE']
Exercise
Rename columns.
df.(columns={})
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.