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

冷暖自知 提交于 2019-11-30 23:54:39

问题


I reproduce the code of book python for data analysis in page 38

I write

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

and prop_cumsum.searchsorted(0.5)

Then there is an error say:

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' 

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

In [49]:

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


回答1:


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)

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

See the online docs



来源:https://stackoverflow.com/questions/22669208/attributeerror-series-object-has-no-attribute-searchsorted-pandas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!