[英]Check if value in dataframe exists in another column for each row
Dataframe in question, df:有问题的数据框,df:
colA colB
1 [1, 4, 5]
4 [3, nan, nan]
I'm trying to return a Series which has True where colA's value is in colB's value for each row.我试图返回一个具有 True 的系列,其中 colA 的值在每一行的 colB 值中。
The result should be:结果应该是:
True
False
I tried: df.colA.isin(df.colB)
- but that doesn't do the trick because colB's values are in lists我试过: df.colA.isin(df.colB)
- 但这并不能解决问题,因为 colB 的值在列表中
您需要在isin
之前解压列表列
m = pd.DataFrame(df['colB'].tolist(),index=df.index).isin(df['colA']).any(axis=1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.