I have the following np.where statement
df['DCC'] = np.where((df['RxDate'] - df['ABdat']).dt.days > 0, 0, df['DCC']
If the difference between ABdat and RxDate > 0 then it assigns 0 to DCC if not DCC remains as it was.
If the difference between ABdat and RxDate > 0 I would like to assign 0 to DCC and assign another column AbCode == 1 on the same row.
I could write a second np.where statement however I was wondering if it was possible to incorporate multiple responses into np.where
For example
df['DCC'] = np.where((df['RxDate'] - df['ABdat']).dt.days > 0, (0 & df['AbCode']==1), df['DCC']
This did not give an error however it did not toggle AbCode to 1
CodePudding user response:
I would do something like this:
mask = (df['RxDate'] - df['ABdat']).dt.days > 0
df.loc[mask, ['DCC', 'AbcCode']] = [0,1]