replacing the value in new data frame python

只愿长相守 提交于 2021-02-11 13:48:31

问题


As you seen on the image we have three columns so i need to write code that can create new columns called aa and replace when whever see A replace it with 1 or B replace it 2 ETC.

Thank you


回答1:


IIUC use:

df['aa'] = df['categories'].map(df.drop_duplicates('categories').set_index('categories')['WOF'])


来源:https://stackoverflow.com/questions/62656932/replacing-the-value-in-new-data-frame-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!