0

when I running following code

from datetime import datetime

if ((dfyz['year_x'] < datetime.now().year) or ((dfyz['year_x'] == datetime.now().year) and (dfyz['mon'] < datetime.now().month))):
     dfyz['pred_n'] = dfyz['yhat']*dfyz['pct']
elif (((dfyz['year_x'] == datetime.now().year) and (dfyz['mon'] >= datetime.now().month)) or ((dfyz['year_x'] > datetime.now().year))):
       dfyz['pred_n'] = dfyz['yhat']*dfyz['pct_ft']

i am getting following error

ValueError: The truth value of a {type(self).__name__} is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

Please help me in fixing it, i have tried replacing and with & and or with | as well but still get same error

Scott Hunter
  • 48,888
  • 12
  • 60
  • 101
Ashish
  • 115
  • 3
  • 15
  • 1
    What is in `dfyz`? – Scott Hunter Jan 07 '22 at 13:14
  • 2
    This has nothing to do with the `if` statement. You have a Pandas(?) column which contains multiple Boolean values (e.g., `[True, True, False]`), for which no boolean value is assigned. Would you want it to be treated as `True`, because it's not empty? Or `True` because it contains `True`? Or `False` because it contains `False`? Pandas (or whatever) does not make that decision: you have to be explicit and use one of the methods suggested to *produce* a single Boolean value. – chepner Jan 07 '22 at 13:17
  • 1
    Does this answer your question? [Use a.empty, a.bool(), a.item(), a.any() or a.all()](https://stackoverflow.com/questions/38834028/use-a-empty-a-bool-a-item-a-any-or-a-all) – jjramsey Jan 07 '22 at 13:23

0 Answers0