AttributeError:“系列"对象没有属性"searchsorted" pandas [英] AttributeError: 'Series' object has no attribute 'searchsorted' pandas

查看:139
本文介绍了AttributeError:“系列"对象没有属性"searchsorted" pandas 的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在第38页上重现了Python书籍的代码以进行数据分析

I reproduce the code of book python for data analysis in page 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 它仍然无法正常工作 熊猫文件中没有串联的搜索分类方法

I can't understand why i re-install numpy and lib pandas it still can't work It's no searchsorted methode in series in the document of pandas

在[49]中:

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

推荐答案

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

You are probably using a version that is 0.13.0 or later where Series now subclasses NDFrame, you have to now do this to return a numpy array:

prop_cumsum.values.searchsorted(0.5)

按搜索排序是一个numpy函数,而不是Pandas Series函数.

as searchsorted is a numpy function and not a Pandas Series function.

请参见在线文档

这篇关于AttributeError:“系列"对象没有属性"searchsorted" pandas 的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆