Python Answers

How to rename column names in Python Pandas?

Spread the love

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.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.