首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Pandas.Series.quantile()时获取错误

使用Pandas.Series.quantile()时获取错误
EN

Stack Overflow用户
提问于 2015-11-12 09:59:06
回答 1查看 561关注 0票数 0

根据Pandas页面上的文档,我们可以将值列表传递给Pandas系列中的分位数函数。

代码语言:javascript
复制
>>> s = Series([1, 2, 3, 4])
>>> s.quantile(.5)
    2.5
>>> s.quantile([.25, .5, .75])
0.25    1.75
0.50    2.50
0.75    3.25

dtype: float64

在我的系统上尝试同样的操作时,我会得到以下错误。

代码语言:javascript
复制
>>> import pandas as pd
>>> s = pd.Series([1, 2, 3, 4])
>>> s
0    1
1    2
2    3
3    4
dtype: int64
>>> s.quantile(0.5)
2.5
>>> s.quantile([0.25, 0.5, 0.75])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/pandas/core/series.py", line 1324, in quantile
    result = _quantile(valid_values, q * 100)
  File "/usr/lib/python2.7/dist-packages/pandas/compat/scipy.py", line 66, in scoreatpercentile
    idx = per / 100. * (values.shape[0] - 1)
TypeError: unsupported operand type(s) for /: 'list' and 'float'

提前谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-11-12 10:01:27

我认为您正在使用的SciPy版本存在一个问题。您只需查看一下SciPy的哪个版本,您当前版本的熊猫就会依赖并相应地更新SciPy库。

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

https://stackoverflow.com/questions/33668700

复制
相关文章

相似问题

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