2

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?

Ishara Madhawa
  • 3,549
  • 5
  • 24
  • 42
MaMo
  • 569
  • 1
  • 10
  • 27

1 Answers1

4

Try the below, rather than 'inf' as a string:

df.replace(-np.Inf, np.nan)
muzzyq
  • 904
  • 6
  • 14