美文网首页
Python ValueError: The truth val

Python ValueError: The truth val

作者: 王叽叽的小心情 | 来源:发表于2020-09-21 20:10 被阅读0次

这个问题已经出现几次,错误提示:ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

解决方法:把条件表达式里面的 andor改为&|就行

代码展示:

# 错误提示
df_repeat = df_flow.loc[df_flow.source.isin(node_list) or df_flow.target.isin(node_list)]
Traceback (most recent call last):
  File "<ipython-input-112-5f65a2323d55>", line 1, in <module>
    df_repeat = df_flow.loc[df_flow.source.isin(node_list) or df_flow.target.isin(node_list)]
  File "D:\ProgramFiles\anaconda\lib\site-packages\pandas\core\generic.py", line 1478, in __nonzero__
    raise ValueError(
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

# 正确表达
df_repeat = df_flow.loc[df_flow.source.isin(node_list) | df_flow.target.isin(node_list)]

相关文章

网友评论

      本文标题:Python ValueError: The truth val

      本文链接:https://www.haomeiwen.com/subject/iddbyktx.html