根据Pandas页面上的文档,我们可以将值列表传递给Pandas系列中的分位数函数。
>>> 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在我的系统上尝试同样的操作时,我会得到以下错误。
>>> 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'提前谢谢。
发布于 2015-11-12 10:01:27
我认为您正在使用的SciPy版本存在一个问题。您只需查看一下SciPy的哪个版本,您当前版本的熊猫就会依赖并相应地更新SciPy库。
https://stackoverflow.com/questions/33668700
复制相似问题