Reputation: 283
have a df with values
df
0 1
sun NaN
moon 123
cat NaN
dog yatch
Turn the values that are already present to pass and NaN to fail
expected Output
0 1
sun fail
moon pass
cat fail
dog pass
Upvotes: 2
Views: 43
Reputation: 7510
A variation without numpy
:
mask = df[1].isna()
df.loc[mask, 1] = 'fail'
df.loc[~mask,1] = 'pass'
Upvotes: 0
Reputation: 862611
Use numpy.where
with Series.isna
:
df[1] = np.where(df[1].isna(), 'fail', 'pass')
Upvotes: 5