Python’s rename column is a method used to change the column nambes with Pandas’ rename function. It’s useful when we load a tabular dataset that has no column names or if we want to assign different names to specific columns.
Its syntax is given as:
d is a dictionary, & the keys are the columns we want to change. The values are the new names for these columns. The code
inplace = False means the result would be stored in a new DataFrame instead of the original one.
We have the following dataset called
With this dataset, we want to do the following:
- Rename the
Income& assign it to
- Finally, print the updated dataframe
When we run the above code, it produces the following result: