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
  • 4,419
  • 2
  • 23
  • 51
king_sules
  • 39
  • 5

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
  • 4,419
  • 2
  • 23
  • 51