在这些方面回家的规范/最简单方法是什么?
答案 0 :(得分:2)
import pandas as pd
from numpy import diff, concatenate
ff = pd.DataFrame( #acquire data here
columns=('Year','Recon'))
fd = diff(ff['Recon'], axis=-1)
ff['diff'] = concatenate([[0],fd],axis=0)
ff['rolling10'] = pd.rolling_mean(ff['diff'],10)
ff['rolling5'] = pd.rolling_mean(ff['diff'],5)
ff.plot('Year',['rolling5','rolling10'],subplots=False)
但请注意!我的测试数据均匀采样。看似rolling_*
不适用于不规则的时间序列,但有一些解决方法:Pandas: rolling mean by time interval