0

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, pred_n should be equal to yhatpct else it should be yhatpct_ft. trying following syntax:

if((dfyz['year_x'] <     datetime.now().year) | ((dfyz['year_x'] == datetime.now().year) & (dfyz['mon'] < datetime.now().month))):
    dfyz['pred_n'] = dfyz['yhat']*dfyz['pct']
else:
    dfyz['pred_n'] = dfyz['yhat']*dfyz['pct_ft']

but i am not getting anything for else condition

2
  • You need to use df.loc. For example, df.loc[your_condition, column_to_update] = updated_value Commented Sep 15, 2021 at 18:50
  • i am not sure how that will help, I am able to get rid of error but now it is not checking if and else condition stackoverflow.com/questions/69201432/… Commented Sep 16, 2021 at 1:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.