Pandas - replacing column values

后端 未结 3 607
温柔的废话
温柔的废话 2020-11-27 16:58

I know there are a number of topics on this question, but none of the methods worked for me so I\'m posting about my specific situation

I have a dataframe that looks

3条回答
  •  借酒劲吻你
    2020-11-27 17:28

    Can try this too!
    Create a dictionary of replacement values.

    import pandas as pd
    data = pd.DataFrame([[1,0],[0,1],[1,0],[0,1]], columns=["sex", "split"])
    

    replace_dict= {0:'Female',1:'Male'}
    print(replace_dict)
    

    Use the map function for replacing values

    data['sex']=data['sex'].map(replace_dict)
    

    Output after replacing

提交回复
热议问题