how to replace 0 with nan 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: replace "-" for nan in dataframe

df.replace(np.nan,0)

Example 3: how to replace zero with null in python

data['amount']=data['amount'].replace(0, np.nan)
data['duration']=data['duration'].replace(0, np.nan)

Example 4: how to replace zero with null in python

df2.loc[df2['Weight'] == 0,'Weight'] = np.nan
df2.loc[df2['Height'] == 0,'Height'] = np.nan
df2.loc[df2['BootSize'] == '0','BootSize'] = np.nan
df2.loc[df2['SuitSize'] == '0','SuitSize'] = np.nan