3

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?

2
  • df.replace(-np.inf, np.nan)? Commented Jun 13, 2018 at 14:03
  • df.replace(np.NINF, np.nan)? Commented Jun 13, 2018 at 14:03

1 Answer 1

5

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

df.replace(-np.Inf, np.nan)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.