Suppose I have the following data:
import pandas as pd
import numpy as np
import datetime as dt
idx = pd.date_range("2010/01/01", "2020/01/01", freq='1T')
n = len(idx)
data = pd.DataFrame({'A': np.random.random(n), 'B': np.random.random(n), 'C': np.random.random(n)}, index=idx)
I can very quickly calculate the exponential moving average of this with halflife 1 hour with:
data.ewm(halflife=60).mean()
However, if I try:
data.ewm(halflife=dt.timedelta(hours=1), times=data.index).mean()
It is very slow (to the point of exiting the code). Why is this?