首页 > 解决方案 > 检查值是否是其他列 Pandas Python 中值的一部分

问题描述

我想检查“ket”列中的值是否在“Ref”列中。我使用此代码来执行此操作

df['Check'] = df.apply(lambda x: x.ket in x.Ref, axis=1)

但它会出现这样的错误:

TypeError: argument of type 'int' is not iterable

这是我的样本数据

参考
712 712,713
673 652
778 654,778

预期结果 :

参考 查看
712 712,713 真的
673 652 错误的
778 654,778 真的

请帮忙

标签: pythonpandasdataframe

解决方案


这段代码对我有用。你可以试试这个:

df['Check'] = df.astype(str).apply(lambda x: x['ket'] in x['Ref'], axis=1)

推荐阅读