How To Check If A Value In One Dataframe Is Present In Keys In The Other Dataframe
I have two dataframes: df_1: Letters Boolean a Nan b Nan c Nan df_2: a b d 2.7 1.2 3.6 1 2
Solution 1:
Use numpy.where
with isin
:
df1['Boolean'] = np.where(df1['Letters'].isin(df2.columns), 'x', np.nan)
Solution 2:
You need :
df1['Boolean']=df1.Letters.isin(df2.columns).map({True:'x',False:np.nan})
print(df1)
Letters Boolean0 a x
1 b x
2 c NaN
Post a Comment for "How To Check If A Value In One Dataframe Is Present In Keys In The Other Dataframe"