我真的不明白为什么它会返回NaN
我有一个df,我需要根据其他列值再创建一个列,此方法始终有效。
train.loc[(train.region == 'Latin America') & (train.sales_channel == 'Online'), 'expense'] = 47
train.loc[(train.region == 'Latin America') & (train.sales_channel == 'Partnerships'), 'expense'] = 63
train.loc[(train.region == 'Latin America') & (train.sales_channel == 'Direct Sales'), 'expense'] = 89
train.loc[(train.region == 'Europe') & (train.sales_channel == 'Online'), 'expense'] = 69
我回来了
答案 0 :(得分:0)
尝试以下
train.loc[(train['region'] == 'Latin America') & (train['sales_channel'] == 'Partnerships'),['expense']] = 63