Renaming DataFrame Columns Using Dictionaries & Lists
Python
Here we have two examples of how to rename columns in a Pandas DataFrame.
In the 1st example we rename a single column by using the rename function and passing a dictionary as a parameter containing the current column name as the key and new column name as the value.
In the 2nd example we simply use a list to set the names of all columns in the dataframe.
1| #Rename Columns with a Dictionary using rename 2| df.rename(columns={'Order_Date' :'Date'},inplace=True) 3| 4| #Rename all columns with a list 5| df.columns = ['col_1','col_2','col_3']
133
121
117
109