Reputation: 67
I have a dataframe df where there are 3 columns
id code status
1 US Y
2 IN Y
3 UK Y
4 CN Y
5 KR Y
I want to update column status to N where code not in ("US", "UK")
I tried using this but failed
df.loc[df['code'] not in ("US","UK"),["status"]] ='N'
Upvotes: 0
Views: 38
Reputation: 79208
df['status'] = df.apply(lambda x: 'N' if x[1] not in ['US','UK'] else x[2],axis=1)
Upvotes: 1
Reputation: 13401
You need:
df['status'] = np.where(df['code'].isin(["US","UK"]), df['status'], 'N')
Upvotes: 1