0

I have a df

.. Doc2 DayType
.. NaN 0
.. PQ Holiday
.. NaN Holiday
.. PJ 0

I have to form a new column 'AssistanceFactor' such that its value is 1 if Doc2 is NaN and DayType is 'Holiday'

1 if Doc2 is not Nan and DayType is 'Holiday'

0.75 if Doc2 is not Nan and DayType is not 'Holiday'

1 if Doc2 is not NaN and DayType is not 'Holiday'

What would be the best method for this? I tried iterrows and conditions as well as np.select /where. But I am not getting the hang of it.

Thanks in advance

dratoms
  • 159
  • 11

1 Answers1

1

Because 3 conditions return 1 and one return 0.75 is possible test only 3rd condition:

df['AssistanceFactor'] = np.where(df.Doc2.notna() & df.DayType.ne('Holiday'), 0.75, 1)
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252