这个问题已经出现几次,错误提示:ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
解决方法:把条件表达式里面的 and
和or
改为&
和|
就行
代码展示:
# 错误提示
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)]
网友评论