首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >ValueError: Bin边沿必须是唯一的:

ValueError: Bin边沿必须是唯一的:
EN

Stack Overflow用户
提问于 2017-06-19 20:15:21
回答 1查看 12.3K关注 0票数 4

我正在尝试使用以下方法计算两列的百分位数:

代码语言:javascript
运行
复制
my_df['float_col_quantile'] = pd.qcut(my_df['float_col'], 100, labels=False)
my_df['int_col_quantile'] = pd.qcut(my_df['int_col'].astype(float), 100, labels=False)

float_col_quantile工作正常,但列int_col_quantile有以下错误。知道我在这里做错了什么吗?我怎样才能解决这个问题?谢谢!

代码语言:javascript
运行
复制
ValueError                                Traceback (most recent call last)
<ipython-input-19-b955e0b00953> in <module>()
      1 my_df['float_col_quantile'] = pd.qcut(my_df['float_col'], 100, labels=False)
----> 2 my_df['int_col_quantile'] = pd.qcut(my_df['int_col'].astype(float), 100, labels=False)


/usr/local/lib/python3.4/dist-packages/pandas/tools/tile.py in qcut(x, q, labels, retbins, precision)
    173     bins = algos.quantile(x, quantiles)
    174     return _bins_to_cuts(x, bins, labels=labels, retbins=retbins,
--> 175                          precision=precision, include_lowest=True)
    176 
    177 

/usr/local/lib/python3.4/dist-packages/pandas/tools/tile.py in _bins_to_cuts(x, bins, right, labels, retbins, precision, name, include_lowest)
    192 
    193     if len(algos.unique(bins)) < len(bins):
--> 194         raise ValueError('Bin edges must be unique: %s' % repr(bins))
    195 
    196     if include_lowest:

ValueError: Bin edges must be unique: array([  1.,   1.,   1.,   1.,   1.,   1.,   1.,   1.,   1.,   1.,   1.,
         1.,   1.,   1.,   1.,   1.,   1.,   1.,   1.,   1.,   1.,   1.,
         1.,   1.,   1.,   1.,   2.,   2.,   2.,   2.,   2.,   2.,   2.,
         2.,   2.,   2.,   2.,   2.,   2.,   2.,   2.,   2.,   2.,   2.,
         2.,   2.,   2.,   2.,   2.,   2.,   2.,   2.,   2.,   2.,   2.,
         2.,   2.,   2.,   2.,   2.,   2.,   2.,   2.,   2.,   2.,   2.,
         2.,   2.,   2.,   4.,   4.,   4.,   4.,   4.,   4.,   4.,   4.,
         4.,   4.,   4.,   4.,   4.,   4.,   4.,   4.,   4.,   4.,   4.,
         4.,   4.,   4.,   4.,   4.,   4.,   4.,   4.,   8.,   8.,   8.,
         8.,  10.])
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-09-14 15:37:05

问题是,pandas.qcut选择回收箱,以便在每个bin/分位数中有相同数量的记录,但相同的值不能落在多个桶/分位数中。

Here是一系列解决方案。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44639189

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档