This question already has answers here:
Closed 2 years ago.
I want to replace the -inf values in a pandas.series feature (column of my dataframe) to np.nan, but I could not make it.
I have tried:
df[feature] = df[feature].replace(-np.infty, np.nan)
df[feature] = df[feature].replace(-np.inf, np.nan)
df[feature] = df[feature].replace('-inf', np.nan)
df[feature] = df[feature].replace(float('-inf'), np.nan)
But it does not work. Any ideas how to replace these values?
Edit:
df[feature] = df[feature].replace(-np.inf, np.nan)
works
BUT:
df = df.replace(-np.inf, np.nan)
does not work.