什么序列方法取代了searchsorted?

2024-10-02 08:18:07 发布

您现在位置:Python中文网/ 问答频道 /正文

在他的视频中,[Data analysis In Python with pandas](http://youtu.be/w26x-z-BdWQ?t=2h14s)中,Wes McKinney提出了一个系列方法,名为searchsorted(),它给出了一个值,并返回了序列穿过该值的索引。此功能似乎不再可用,是否有其他功能替代它?在


Tags: 方法in功能httppandasdata视频with
1条回答
网友
1楼 · 发布于 2024-10-02 08:18:07

我相信这是由于Pandas 0.13.0中发生的重构,其中Pandas Series现在是NDFrame的子类,而不是ndarray参见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行x 1列]

^{pr2}$

现在比较一下使用numpy数组会发生什么:

In [29]:

temp = np.array(arange(10))

In [32]:

temp.cumsum().searchsorted(11)
Out[32]:
5

相关问题 更多 >

    热门问题