Python 为什么使用pandas的布尔if语句会创建错误?
我如何格式化它以便能够使用if语句进行测试Python 为什么使用pandas的布尔if语句会创建错误?,python,pandas,dataframe,valueerror,Python,Pandas,Dataframe,Valueerror,我如何格式化它以便能够使用if语句进行测试 result = dfrow.str.contains('Animation') x = 0 print(result) if result == False: x = 1 if result == True: x = 2 打印功能输出: 1 False Name: genres, dtype: bool 给出的错误是: ----> 4 if result == False: ValueError: The trut
result = dfrow.str.contains('Animation')
x = 0
print(result)
if result == False:
x = 1
if result == True:
x = 2
打印功能输出:
1 False
Name: genres, dtype: bool
给出的错误是:
----> 4 if result == False:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
对于这个场景,您似乎将使用一行数据帧。然后你可以用
dfrow.str.contains('Animation').iloc[0]
instead of
dfrow.str.contains('Animation')
为什么他只想使用第一个值?@ansev即使我们输出多个值,下一步也会中断,因为op将其视为单个真或假变量,可能是