Python 基于多个值检查和更新列

Python 基于多个值检查和更新列,python,python-3.x,dataframe,Python,Python 3.x,Dataframe,我有一个数据帧df,其中有3列 id code status 1 US Y 2 IN Y 3 UK Y 4 CN Y 5 KR Y 我想将列状态更新为N,其中代码不在(“美国”、“英国”) 我试着用这个,但失败了 df.loc[df['code'] not in ("US","UK"),["status"]] ='N' 你需要: df['status'] = np.where(df['code'].isin(["US","UK"]

我有一个数据帧df,其中有3列

id code  status   
1  US    Y      
2  IN    Y
3  UK    Y
4  CN    Y
5  KR    Y 
我想将列状态更新为N,其中
代码不在(“美国”、“英国”)

我试着用这个,但失败了

df.loc[df['code'] not in ("US","UK"),["status"]] ='N'
你需要:

df['status'] = np.where(df['code'].isin(["US","UK"]), df['status'], 'N')
你需要:

df['status'] = np.where(df['code'].isin(["US","UK"]), df['status'], 'N')
可能的重复可能的重复