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

て烟熏妆下的殇ゞ 提交于 2019-12-14 02:21:26

问题


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:


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

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


来源:https://stackoverflow.com/questions/41475470/pd-qcut-with-values-that-are-inf-infinity-valueerror-bin-edges-must-be-unique

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!