In his video, [Data analysis in Python with pandas] (http://youtu.be/w26x-z-BdWQ?t=2h14s), Wes McKinney presents a series method names searchsorted(), which given a value, gives back the index in which the series is crossing that value. It appears this function is not available any more, did something else replace it?
searchsorted() function is used to find the indices into a sorted array arr such that, if elements are inserted before the indices, the order of arr would be still preserved. Here, binary search is used to find the required insertion indices.
The pandas series constructor will automatically create series index labels based on the given data. If you want to specify those index labels, we can give those index values separately by using the index keyword argument of the pandas series function.
I believe this is due to the refactoring that occurred in Pandas 0.13.0 where Pandas Series now sub-class NDFrame rather than ndarray see this:
In [33]:
import pandas as pd
import numpy as np
df = pd.DataFrame({'a':arange(10)})
df
Out[33]:
a
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
[10 rows x 1 columns]
[10 rows x 3 columns]
In [28]:
# you now have to call `.values` to return a ndarray
df.a.values.cumsum().searchsorted(11)
Out[28]:
5
Now compare what happens if we use a numpy array:
In [29]:
temp = np.array(arange(10))
In [32]:
temp.cumsum().searchsorted(11)
Out[32]:
5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With