Renaming column names in Pandas

Created by lexualLinked to 69.6m issues across 214 teams


Renaming columns in a Pandas DataFrame is a simple process. To do this, use the df.rename() function and specify the columns to be renamed. You can either create a new DataFrame with the renamed columns or rename the existing DataFrame (in place).

df = df.rename(columns={'oldName1': 'newName1', 'oldName2': 'newName2'}) # Or rename the existing DataFrame (rather than creating a copy) df.rename(columns={'oldName1': 'newName1', 'oldName2': 'newName2'}, inplace=True)

And that's it! You have successfully renamed the columns in your DataFrame.