Reputation: 690
I want to know if there is an easier way to replace a value with other when it is NaN, other than:
var = a if not pd.isnull(a) else b
The idea would be to avoid having to have to use the variable a
Upvotes: 2
Views: 191
Reputation: 862851
Simplier is use notna
if working with scalars:
var = a if pd.notna(a) else b
In column use Series.notna
:
df['col'] = df['col'].mask(df['col'].notna(), a)
df.loc[df['col'].notna(), 'col'] = a
Upvotes: 3