how to replace zero with null in python

Solutions on MaxInterview for how to replace zero with null in python by the best coders in the world

showing results for - "how to replace zero with null in python"
Lautaro
21 Mar 2017
1data['amount']=data['amount'].replace(0, np.nan)
2data['duration']=data['duration'].replace(0, np.nan)
Marta
12 Jul 2018
1df2[["Weight","Height","BootSize","SuitSize"]].astype(str).replace('0',np.nan)
Elisa
24 May 2018
1df2.loc[df2['Weight'] == 0,'Weight'] = np.nan
2df2.loc[df2['Height'] == 0,'Height'] = np.nan
3df2.loc[df2['BootSize'] == '0','BootSize'] = np.nan
4df2.loc[df2['SuitSize'] == '0','SuitSize'] = np.nan