pd.qcut with values that are inf (infinity) ValueError: Bin edges must be unique:

1.3k views Asked by At

I have a data set that is a ratio of 2 float type numbers. Some values have inf for infinity (divide by zero) situation. How do I work with pd.qcut/pd.cut with inf values?

My data can be accessed here.

q = pd.qcut(df['ratio'], 10)

ValueError: Bin edges must be unique: array([  1.20089207e+03,   6.02984295e+04,   1.26445577e+05,
         2.29982770e+05,   5.13176079e+05,   1.28794976e+06,
         4.96001538e+06,              nan,              nan,
                    nan,              inf])
1

There are 1 answers

2
piRSquared On BEST ANSWER

you could replace the np.inf with np.nan then dropna

q = pd.qcut(df.ratio.replace(np.inf, np.nan).dropna(), 10)