Loc function on conditions in pandas returns Nan

1.2k Views Asked by At

I genuinely don't get why it returns NaN

I have a df and i need to create one more column based on other columns values, this method always worked.

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

and i get back this

enter image description here

1

There are 1 best solutions below

0
On

Try the following

train.loc[(train['region'] == 'Latin America') & (train['sales_channel'] == 'Partnerships'),['expense']] = 63