1

I have a series values and I want to print 'Bigger' for each value bigger than zero

    if(ser > 0)
      print 'Bigger' 

python gives me the error:

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

A.Kot
  • 7,615
  • 2
  • 22
  • 24
Tarik Ziyad
  • 115
  • 1
  • 10
  • 1
    What are you really trying to do - I'm guessing not print "bigger" N many times...? `ser[ser > 0]` will return you a new series of values greater than zero... – Jon Clements Sep 13 '17 at 17:32

1 Answers1

2

Can't compare an entire series, have to iterate through

for i in ser:
    if i>0:
        print('Bigger')

If you'd like to see the values alongside the word bigger, simply print(i, 'Bigger')

For a more pythonic syntax, consider list comprehension:

['Bigger' for i in ser if i>0]
A.Kot
  • 7,615
  • 2
  • 22
  • 24