不推荐使用pd.rolling_mean-ndarrays的替代方法 [英] pd.rolling_mean becoming deprecated - alternatives for ndarrays

查看:831
本文介绍了不推荐使用pd.rolling_mean-ndarrays的替代方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

pd.rolling_mean似乎已弃用ndarrays

 pd.rolling_mean(x, window=2, center=False)

未来警告:ndarrays不推荐使用pd.rolling_mean,并将在以后的版本中将其删除

FutureWarning: pd.rolling_mean is deprecated for ndarrays and will be removed in a future version

,但根据此SO答案

but it seems to be the fastest way of doing this, according to this SO answer.

现在是否有新的方法可以直接用SciPy或NumPy做到与pd.rolling_mean一样快?

Are there now new ways of doing this directly with SciPy or NumPy that are as fast as pd.rolling_mean?

推荐答案

编辑-不幸的是,新方法似乎没有这么快:

EDIT -- Unfortunately, it looks like the new way is not nearly as fast:

新版熊猫:

In [1]: x = np.random.uniform(size=100)

In [2]: %timeit pd.rolling_mean(x, window=2)
1000 loops, best of 3: 240 µs per loop

In [3]: %timeit pd.Series(x).rolling(window=2).mean()
1000 loops, best of 3: 226 µs per loop

In [4]: pd.__version__
Out[4]: '0.18.0'

旧版本:

In [1]: x = np.random.uniform(size=100)

In [2]: %timeit pd.rolling_mean(x,window=2)
100000 loops, best of 3: 12.4 µs per loop

In [3]: pd.__version__
Out[3]: u'0.17.1'

这篇关于不推荐使用pd.rolling_mean-ndarrays的替代方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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