哪些Series方法取代了searchsorted? [英] What Series method replaced searchsorted?

查看:67
本文介绍了哪些Series方法取代了searchsorted?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在他的视频中,[使用pandas在Python中进行数据分析]( http://youtu .be/w26x-z-BdWQ?t = 2h14s ),韦斯·麦金尼(Wes McKinney)提出了一系列方法名称searchsorted(),该方法名赋予一个值,并返回该系列与该值相交的索引.似乎该功能不再可用,是否有其他替代功能?

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?

推荐答案

我认为这是由于Pandas 0.13.0中发生的重构所致,其中Pandas Series现在将NDFrame子类化,而不是ndarray参见

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行x 1列]

[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

现在比较如果我们使用numpy数组会发生什么:

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

这篇关于哪些Series方法取代了searchsorted?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆