0

How do I format this to be able to test with an if statement?

result = dfrow.str.contains('Animation')
x = 0
print(result)
if result == False:
    x = 1
if result == True:
    x = 2

The print function outputs:

1    False

Name: genres, dtype: bool

The error given:

----> 4 if result == False:

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
pppery
  • 3,731
  • 22
  • 33
  • 46
  • 1
    Possible duplicate of [Truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()](https://stackoverflow.com/questions/36921951/truth-value-of-a-series-is-ambiguous-use-a-empty-a-bool-a-item-a-any-o) – pppery Oct 24 '19 at 02:58

1 Answers1

0

It seems you will be using a 1 row dataframe for this scenario. Then you can use

dfrow.str.contains('Animation').iloc[0]
 instead of 
dfrow.str.contains('Animation')
Suraj Motaparthy
  • 520
  • 1
  • 5
  • 12