如何防止pd.ewma更改索引?

时间:2018-06-25 12:19:47

标签: python pandas time-series resampling

我正在使用以下代码重新采样我的时间序列数据:

bars = transactions.price.resample('4H', base = 3).ohlc()

这使我能够正确考虑DST。输出为:

timestamp
2017-12-31 07:00:00    12668.5
2017-12-31 11:00:00    13183.0
2017-12-31 15:00:00    13124.0
2017-12-31 19:00:00    13178.5
2017-12-31 23:00:00    13130.5

我现在想使用pandas .rolling函数并尝试以下操作来计算移动平均线:

ma_rolling = pd.ewma(bars['close'], span=20, freq='4H') 

这弄乱了时间间隔,将其转换为偶数小时:

timestamp
2017-12-31 04:00:00    14006.251358
2017-12-31 08:00:00    13927.838526
2017-12-31 12:00:00    13851.275461
2017-12-31 16:00:00    13787.196295
2017-12-31 20:00:00    13724.649100

是否可以在ewma函数中指定基数/移位并保留原始索引? .rolling函数不会像这样运行并保留原始索引。

0 个答案:

没有答案