I have a sample from my dataframe:
Created Insert Time MatchKey In Previous New Type
18593 2016-08-12 2018-02-19 LXGS0903
You can use pd.Series.mask for exactly this purpose:
df['New Type'].mask(df['In Previous']=='Yes', 'In Previous', inplace=True)
Somewhat confusingly, you have to remember that pd.Series.mask
updates a value when a condition is met, while pd.Series.where
updates a value when a condition is not met.
Just return the column instead of pass
this is the same as doing nothing when the condition is False
:
current['New Type'] = np.where(current['In Previous']=='Yes','In Previous',current['New Type'] )
Or you can just mask those rows:
current['New Type'] = current.loc[current['In Previous']=='Yes', 'In Previous']