replace inf with 0 in python pandas code example
Example 1: pandas dataframe replace inf
df.replace([np.inf, -np.inf], np.nan)
Example 2: how to replace zero value in python dataframe
nonzero_mean = df[ df.col != 0 ].mean()
df.replace([np.inf, -np.inf], np.nan)
nonzero_mean = df[ df.col != 0 ].mean()