ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() ora.l

小白随手记录改bug过程
if G.nodes[node] == source:
    print(type(G.nodes[node]))

开始的代码,报错如标题,分析应该是将一个值与多个值或一个列表中的值相比较、匹配的原因,source是一个列表有多个值,遂改成如下

if G.nodes[node] in source:
    print(type(G.nodes[node]))

然后又报错,TypeError: unhashable type: 'dict',于是考虑把字典的数据类型转成字符串

if str(G.nodes[node]) in source:
    print(type(G.nodes[node]))

程序不报错了,运行成功

你可能感兴趣的:(python)