0
votes
a=np.arange(1,10)
b=pd.Series(a)
print(a==b)

output: 0. True

  1. True
  2. True ...
  3. True

but when I made it in a loop

if (a==b):
   print('True')

output: ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

1

1 Answers

0
votes

a==b will give a Series, so if you want check if all the values are the same, try:

if (a==b).all():
    print('True')

If you want to check if any of the values are the same:

if (a==b).any():
    print('True')

In this case the two codes all output:

True