fill nan values in pandas code example

Example 1: how to replace nan with 0 in pandas

df['product']=df['product'].fillna(0)
df['context']=df['context'].fillna(0)
df

Example 2: find nan values in a column pandas

df.isnull().values.any()

Example 3: pandas replace nan

data["Gender"].fillna("No Gender", inplace = True)

Example 4: how to replace nan values with 0 in pandas

df.fillna(0)

Example 5: find nan values in a column pandas

df.isnull().sum().sum()

Example 6: replace nan using fillna

>>> df.fillna(0)
    A   B   C   D
0   0.0 2.0 0.0 0
1   3.0 4.0 0.0 1
2   0.0 0.0 0.0 5
3   0.0 3.0 0.0 4