As written in the title, I need to replace -inf values within a pandas data frame. I would like to replace them by nan-values. There are multiple columns containing -inf so it should be run over the whole data frame.
I tried df.replace(np.inf, np.nan) which only seems to work with positive infinity. Also tried df.replace('-inf', np.nan).
How do I replace negative infinity values in my dataframe?
Try the below, rather than 'inf' as a string:
df.replace(-np.Inf, np.nan)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With