I am trying to use the where function while ignoring Nan, I do not wish to drop or replace the Nans.
Here a toy data set:
df=pd.DataFrame({
'A':[8,39,40,52],
'B':[8,39,np.nan,50],
})
Which gives:
A B
0 8 8.0
1 39 39.0
2 40 NaN
3 52 50.0
Desired result:
A B check
0 8 8.0 True
1 39 39.0 True
2 40 NaN Nan
3 52 50.0 False
I tried the following code but it did not work:
df = ((np.where(df['A']== df['B'], True, False))| df.isnull())