How to rename column names in Python Pandas?

To rename column names in Python Pandas, we call the dataframe rename method.

For instance, we write

df = df.rename(columns={'oldName1': 'newName1', 'oldName2': 'newName2'})

to rename the oldName1 and oldName2 columns to newName1 and newName2 with df.rename.

And then we assign the returned dataframe back to df.