Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
532 views
in Technique[技术] by (71.8m points)

python - pd.rolling_mean becoming deprecated - alternatives for ndarrays

EDIT: This question was asked in 2016 and similar questions have been posted on SO years later after the functionality was finally removed, e.g. module 'pandas' has no attribute 'rolling_mean'

However, the question concerns performance of the new pd.rolling.mean() and should stay open until the associated pandas issue is fixed.


It looks like pd.rolling_mean is becoming deprecated for ndarrays,

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

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

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

New version of Pandas:

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'

Old version:

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'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...