I want to create a new_column
with merging df
and df2
(df=pd.merge(df,df2, how='left', on='Type')
), but only if df['Type']=='certain_value'
So if with a normal merge the new_column would be completely filled, I would like a bunch of NaNs and only keep values where a certain condition is met from another column.
Is there a way of doing this?
I've tried replacing values with NaN after merging but am struggling with that too:
np.where(df['Type']!='certain_value', np.NaN, df['new_column'])
which doesn't do what I would like it to.