Issue
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
Solution
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)
Answered By - jezrael
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.