Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 684
user3465447 Avatar asked Mar 26 '14 17:03

user3465447


1 Answers

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

like image 171
EdChum Avatar answered Oct 06 '22 20:10

EdChum