我试图compare two columns
的一个数据帧,但它的结果是错误的。PFB代码:
if((df3.name==df3.KEY) and (df3.id==df3.seq_id)):
print("hey")
else:
print("hey1")
其中df3
是数据帧。它抛出以下错误:
raise ValueError("Cannot convert column into bool: please use '&' for 'and', '|' for 'or', "
ValueError: Cannot convert column into bool: please use '&' for 'and', '|' for 'or', '~' for 'not' when building DataFrame boolean expressions.
我在SO blog中尝试了几种解决方案,并将操作符从and
更改为&
,但都没用
我尝试转换到pandas
,然后执行操作,它在shell中运行良好,但在IDE中不起作用:
df4 = df3.toPandas()
if(df4['name'].equals(df4['KEY']) & df4['id'].equals(2)):
print("hey")
else:
print("hey1")
目前没有回答
相关问题 更多 >
编程相关推荐