Renaming DataFrame Columns Using Dictionaries & Lists
Python
Data Preprocessing
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']
4
4
3
3
2
How to Remove Punctuation From Text with Python
Python
Data Preprocessing
Nlp | String | Punctuation
2
2
How to Create Different Aggregations Using GroupBy, Agg & Dictionaries
Python
Data Preprocessing
2
2
2