pandas srt.lower() not working on dataframe column

后端 未结 1 1597
醉话见心
醉话见心 2021-01-20 22:28

I\'m working with the Titanic dataset available from Kaggle. I have it in a dataframe and i want to change the case of the \"sex\" column to lowercase. I\'m using the follow

1条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-20 23:21

    str.lower() does not modify the existing column. It just returns a new Series with the lowercase transform applied. If you want to overwrite the original column, you need to assign the result back to it:

    df['sex'] = df.sex.str.lower()
    

    0 讨论(0)
提交回复
热议问题