I have a simple(and long) Panda DF with Datetime Index and Prices, I am trying to create a new Column ['ewm_12'] which pick 11 previous rows every 120 minutes appends current price and calculates the ewm
I am trying to do it in a vectorized fashion as the DF is long, using the following code:
dftemp['ewm_12'] = dftemp.loc[dftemp.index::120][-11:].append(dftemp.loc[(dftemp.index)])[dfs].ewm(min_periods=12,span=12, adjust = True).mean()[-1:][0]
TypeError: Cannot convert input [DatetimeIndex(['2018-01-01 22:00:00+00:00', '2018-01-01 22:01:00+00:00','2019-01-18 22:00:00+00:00'],dtype='datetime64[ns, Europe/London]', length=394561, freq=None)] of type to Timestamp
This seem very strange as if i pick just one row dftemp.index it returns a Timestamp but when I ask it to iterate over the whole df.index it says it cannot convert the Datetimeindex (which is a collection of Timestamps), I can do it with a for loop but will take several minutes and I am sure there must be a way if someone knows pls help