Examples
import numpy as np
import pandas as pd
df = pd.DataFrame({'Q': [0, 2, 3, np.nan, 6]})
df
Rolling sum with a window length of 2, using the ‘triang’ window type.
df.rolling(2, win_type='triang').sum()
Rolling sum with a window length of 2, min_periods defaults to the window length.
df.rolling(2).sum()
Same as above, but explicitly set the min_periods
df.rolling(2, min_periods=1).sum()
A ragged (meaning not-a-regular frequency), time-indexed DataFrame
df = pd.DataFrame({'Q': [0, 2, 3, np.nan, 6]},
index = [pd.Timestamp('20190201 09:00:00'),
pd.Timestamp('20190201 09:00:02'),
pd.Timestamp('20190201 09:00:03'),
pd.Timestamp('20190201 09:00:05'),
pd.Timestamp('20190201 09:00:06')])
df
Contrasting to an integer rolling window, this will roll a variable length window corresponding
to the time period. The default for min_periods is 1.
df.rolling('2s').sum()