If Else Not Checking Both Of The Conditions In Python
i want new column ['pred_n'] to be created based on certain condition, condition is as follows: if year is less than or equal to current year & month is less than current month
Solution 1:
You are currently using the bitwise operators |
and &
, rather than the logical operators or
and and
. Presumably you really want something like:
now = datetime.now()
if (dfyz['year_x'] < now.year or
dfyz['year_x'] == now.year and dfyz['mon'] < now.month
):
...
(Its not great practice to keep calling now
several times ... each of your calls is potentially returning a different value for now)
Post a Comment for "If Else Not Checking Both Of The Conditions In Python"