简体   繁体   中英

Renaming a subset of the columns in a pandas Dataframe

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"})

在此处输入图像描述

You just have to reassign the code to df4 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM