df['product']=df['product'].fillna(0)
df['context']=df['context'].fillna(0)
df
pandas.DataFrame.fillna(0)
df.fillna(0)
a[a==0] = np.nan
df = df.astype("object").where(pd.notnull(df), None)
In [7]: df
Out[7]:
0 1
0 NaN NaN
1 -0.494375 0.570994
2 NaN NaN
3 1.876360 -0.229738
4 NaN NaN
In [8]: df.fillna(0)
Out[8]:
0 1
0 0.000000 0.000000
1 -0.494375 0.570994
2 0.000000 0.000000
3 1.876360 -0.229738
4 0.000000 0.000000
DataFrame.fillna()
numpy.nan_to_num(x, copy=True, nan=0.0, posinf=None, neginf=None)
In [1]: df = DataFrame([[True, True, False],[False, False, True]]).T
In [2]: df
Out[2]:
0 1
0 True False
1 True False
2 False True
In [3]: df.applymap(lambda x: 1 if x else np.nan)
Out[3]:
0 1
0 1 NaN
1 1 NaN
2 NaN 1
df1 = df.where(pd.notnull(df), None)
>>> a = np.arange(3.0)
>>> a
array([ 0., 1., 2.])
>>> a[a==0]
array([ 0.])
>>> a[a==0] = np.nan
>>> a
array([ nan, 1., 2.])
df. replace(np. nan,'',regex=True)