Renaming Columns in a Pandas Dataframe Using Dictionaries & Lists

Python

In this example we rename an individual column using the rename function and a dictionary and then rename all columns using a list.

 1|  # Rename particular columns using a dictionary
 2|  df.rename(columns={'Order_Date' :'Date'},inplace=True)
 3|  
 4|  # Rename all columns using a list
 5|  df.columns = ['col_1','col_2','col_3']
 6|  
Did you find this snippet useful?

Sign up for free to to add this to your code library