0

I can't calculate the mean of a variable because it has infinite values in it, but I can't find and fix them:

perc_df[['variable']].mean()

variable    inf
dtype: float64

I've never dealt with infinite values before, is there an equivalent to "isna()" and "dropna()" for infinite values in pandas? If there isn't, how do I deal with these values?

2 Answers 2

2

You can try to filter out the infinite values with numpy.inf. The code is following:

import numpy as np
perc_df[perc_df.variable != np.inf].variable.mean()
Sign up to request clarification or add additional context in comments.

Comments

1

I think this should work for you:

perc_df = perc_df.replace([np.inf, -np.inf], np.nan)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.