Replace all 0s with nan, and nan with 0

 Select all data with a value of 0 in the dataframe and replace it with nan

df[df == 0] = np.nan

 Select all data with the value of nan in the dataframe and replace with 0

df.fillna(0)

 

Guess you like

Origin blog.csdn.net/ch206265/article/details/108797595