对于某列数据的某个单元格内容,想通过str.contains 判断其是否符合列表中的某个名字,符合则返回真,不符合则返回否;
但优于列表循环传入数据,导致返回的真值不确定,提示错误代码为The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
想问下如何让模糊判断中 有列表中的任何一个为真,则返回真,并顺利运行;
感谢!
a = ['张三','李四','王五']
if df['经办人名称'].str.contains(str(a), na=False):
print('符合')
else:
print('不符合')
---------------------------------------------------------------------------
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
a = ['张三', '李四', '王五']
df=input('经办人名称')
if df in a:
print('符合')
else:
print('不符合')
直接用in方法判断在不在列表里