gpt4 book ai didi

python - 属性错误 : 'Series' object has no attribute 'searchsorted' pandas

转载 作者:太空狗 更新时间:2023-10-29 20:15:43 25 4
gpt4 key购买 nike

我复现python书第38页数据分析的代码

我写

prop_cumsum = df.sort_index(by='prop', ascending=False).prop.cumsum()

and prop_cumsum.searchsorted(0.5)

然后有错误说:

AttributeError                            Traceback (most recent call last)
<ipython-input-30-f2e2bb3f5ba0> in <module>()
----> 1 prop_cumsum.searchsorted(0.5)

C:\Users\xxx\AppData\Local\Enthought\Canopy32\User\lib\site-packages\pandas\core\generic.pyc in __getattr__(self, name)
1813 return self[name]
1814 raise AttributeError("'%s' object has no attribute '%s'" %
-> 1815 (type(self).__name__, name))
1816
1817 def __setattr__(self, name, value):

AttributeError: 'Series' object has no attribute 'searchsorted'

我不明白为什么我重新安装 numpy 和 lib pandas它仍然无法工作pandas文档中没有series的searchsorted方法

在[49]中:

http://nbviewer.ipython.org/github/lexual/pydata-book/blob/35fd20645c75128ae348a275848575e2eae7a025/ch02_us_baby_names.ipynb

最佳答案

您可能正在使用 0.13.0 或更高版本,其中 Series 现在是 NDFrame 的子类,您现在必须执行此操作以返回一个 numpy 数组:

prop_cumsum.values.searchsorted(0.5)

因为 searchsorted 是一个 numpy 函数而不是 Pandas Series 函数。

参见 online docs

关于python - 属性错误 : 'Series' object has no attribute 'searchsorted' pandas,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22669208/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com