Вот еще один способ получить скользящее окно:
Настройка:
d = {pd.Timestamp('2017-12-29 14:44:00'): 69.9,
pd.Timestamp('2017-12-29 14:45:00'): 69.91,
pd.Timestamp('2017-12-29 14:46:00'): 69.87,
pd.Timestamp('2017-12-29 14:47:00'): 69.85,
pd.Timestamp('2017-12-29 14:48:00'): 69.86,
pd.Timestamp('2017-12-29 14:49:00'): 69.92,
pd.Timestamp('2017-12-29 14:50:00'): 69.9,
pd.Timestamp('2017-12-29 14:51:00'): 70.0,
pd.Timestamp('2017-12-29 14:52:00'): 69.97,
pd.Timestamp('2017-12-29 14:53:00'): 69.99,
pd.Timestamp('2017-12-29 14:54:00'): 69.99,
pd.Timestamp('2017-12-29 14:55:00'): 69.85}
ser = pd.Series(d)
Использовать пустой список с rolling
, apply
с append
:
lol = []
ser.rolling(3).apply((lambda x: lol.append(x.values) or 0), raw=False)
lol
Выход:
[array([69.9 , 69.91, 69.87]),
array([69.91, 69.87, 69.85]),
array([69.87, 69.85, 69.86]),
array([69.85, 69.86, 69.92]),
array([69.86, 69.92, 69.9 ]),
array([69.92, 69.9 , 70. ]),
array([69.9 , 70. , 69.97]),
array([70. , 69.97, 69.99]),
array([69.97, 69.99, 69.99]),
array([69.99, 69.99, 69.85])]