Reputation: 11680
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])
Upvotes: 1
Views: 1455
Reputation: 294508
you could replace
the np.inf
with np.nan
then dropna
q = pd.qcut(df.ratio.replace(np.inf, np.nan).dropna(), 10)
Upvotes: 1