I am having an error: Truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
I understood the context of this error but I am unable to fix this. Here ps
is the list of either float
or NnN
that's it. In this case what it has caused it to be ambiguous to handle if statement?
It gives an error on line 3, 5, 9 and lastly at sort statement.
for item in candidates:
print("I am candidate loop \n",item)
ps=2*tmp3[0,i]/((diagonal.loc[x1])["pc"]+(diagonal.loc[item+1])["pc"])
print(ps)
if ps > 0:
if len(out)<k:
out.append([ps, item+1])
else:
if ps > min(out,key=lambda x:x[0])[0]):
out.remove(min(out,key=lambda x:x[0]))
out.append([ps,item+1])
else:
pass
i+=1
out.sort()
out.reverse()
I follwed this solution on this platform also tried this way just in case if all values are greater then zero
The if loop continues but then it gives the same error on out.sort()
.
for item in candidates:
print("I am candidate loop \n",item)
ps=2*tmp3[0,i]/((diagonal.loc[x1])["pc"]+(diagonal.loc[item+1])["pc"])
print(ps)
if (ps > 0).all():
if len(out)<k:
out.append([ps, item+1])
else:
if (ps > min(out,key=lambda x:x[0])[0]).all():
out.remove(min(out,key=lambda x:x[0]))
out.append([ps,item+1])
else:
pass
i+=1
out.sort()
out.reverse()
Any kind of help would be appreciated!
Thanks in advance!