python - 检查值是否是其他列 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 | 真的 |
请帮忙
解决方案
这段代码对我有用。你可以试试这个:
df['Check'] = df.astype(str).apply(lambda x: x['ket'] in x['Ref'], axis=1)
推荐阅读
- customization - Bitrix 组件和模块定制
- javascript - 在 react.js laravel 组合项目中调用 axios 函数定义中的函数
- python - Flask-SQLAlchemy:如何在执行连接操作后返回单个对象的列表?
- nginx - nginx 位置代理显示未找到
- c# - System.InvalidOperationException:附加类型为“QC.Models.Defect”的实体失败,因为另一个相同类型的实体
- c# - 通过c#卸载windows服务后无法删除.exe文件
- python - Python 2.xx 如何在 python 的打印语句中添加逗号而没有前面的空格字符?
- python - PIL 无法正确读取已编辑的 png
- javascript - 为什么我们不在 app.module.ts 的装饰器数组中添加 'ngModule'
- php - 如何创建此数组样式