0

I am trying to rename specific columns in a pandas.DataFrame so I can concat it with a similar dataframe. The code I ran is compiling but it doesn't successfully rename the columns.

df4.rename(columns={"Level1":"PctLevel1","Level2":"PctLevel2","Level3":"PctLevel3","Level4":"PctLevel4"})

enter image description here

Arturo Sbr
  • 5,567
  • 4
  • 38
  • 76
king_sules
  • 39
  • 8

1 Answers1

1

You just have to reassign the code to df4.

df4 = df4.rename(columns={"Level1":"PctLevel1","Level2":"PctLevel2","Level3":"PctLevel3","Level4":"PctLevel4"})

Likewise, you can set the inplace argument to True.

df4.rename(columns={"Level1":"PctLevel1","Level2":"PctLevel2","Level3":"PctLevel3","Level4":"PctLevel4"}, inplace=True)
Arturo Sbr
  • 5,567
  • 4
  • 38
  • 76