To rename columns in dataframe in Pandas python, you can either provide new columns in column property or you can use rename() function.

Consider this code –

>>> superHeroDF = pd.DataFrame({'marvel':["Ironman", "Thor"], 'dc': ["Superman", "Batman"]})
>>> superHeroDF
    marvel   dc
0   Ironman  Superman
1   Thor     Batman

PythonCopy

In this code we have created a panda dataframe with two columns – marvel and dc. In marvel we have two superhero Ironman and Thor while in dc we have Superman and Batman. Suppose, we want to rename columns marvel and dc to avenger and justice league, then we can do it in following ways –

#python #python dataframe #python pandas #python-short

How to Rename Columns in Pandas Python?
1.40 GEEK