Categories
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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *