在他的视频,[在Python数据分析与大熊猫(http://youtu.be/w26x-z-BdWQ?t=2h14s),韦斯·麦金尼呈现searchsorted一系列方法名(),它赋予了价值,还给系列越过该值的索引.看来这个功能不再可用了,还有别的东西取而代之吗?
我相信这是由于发生在熊猫0.13.0其中熊猫系列现在子类NDFrame而非ndarray看到重构此:
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
Run Code Online (Sandbox Code Playgroud)
[10行x 1列]
[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
Run Code Online (Sandbox Code Playgroud)
现在比较一下如果我们使用numpy数组会发生什么:
In [29]:
temp = np.array(arange(10))
In [32]:
temp.cumsum().searchsorted(11)
Out[32]:
5
Run Code Online (Sandbox Code Playgroud)