pd.rolling_mean becoming deprecated - alternatives for ndarrays

前端 未结 5 691
自闭症患者
自闭症患者 2020-12-16 14:09

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

5条回答
  •  攒了一身酷
    2020-12-16 14:21

    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'
    

提交回复
热议问题