pandas create new column based on values from other columns / apply a function of multiple columns, row-wise

后端 未结 5 670
广开言路
广开言路 2020-11-22 06:24

I want to apply my custom function (it uses an if-else ladder) to these six columns (ERI_Hispanic, ERI_AmerInd_AKNatv, ERI_Asian,

5条回答
  •  南方客
    南方客 (楼主)
    2020-11-22 06:43

    .apply() takes in a function as the first parameter; pass in the label_race function as so:

    df['race_label'] = df.apply(label_race, axis=1)
    

    You don't need to make a lambda function to pass in a function.

提交回复
热议问题