By Hemanta Sundaray on 2022-03-14
We can rename individual columns by using the .rename method.
Pass a dictionary like the one below to the columns keyword argument.
{"Old Column Name1" : "New Column Name1", "Old Column Name2" : "New Column Name2"}
Below, we have an Excel table:
Let’s rename AREA to CARPET AREA and ZONE to REGION.
sales.rename(columns={"AREA" : "CARPET AREA", "ZONE" : "REGION"}, inplace=True)
Output:
Note that using
renamewith only thecolumnskeyword will create a new DataFrame, leaving your original DataFrame unchanged. That’s why we also passed in the keyword argumentinplace = True. Usinginplace = Truelets us edit the original DataFrame.