Pandas Series: rolling() function

Rolling window calculations in Pandas

The rolling() function is used to provide rolling window calculations.


Series.rolling(self, window, min_periods=None, center=False, win_type=None, on=None, axis=0, closed=None)
Pandas Series rolling image


Name Description Type/Default Value Required / Optional
window Size of the moving window. This is the number of observations used for calculating the statistic. Each window will be a fixed size.
If its an offset then this will be the time period of each window. Each window will be a variable sized based on the observations included in the time-period. This is only valid for datetimelike indexes.
int, or offset Required
min_periods Minimum number of observations in window required to have a value (otherwise result is NA). For a window that is specified by an offset, min_periods will default to 1. Otherwise, min_periods will default to the size of the window. int
Default Value : None
center Set the labels at the center of the window. bool
Default Value : False
win_type Provide a window type. If None, all points are evenly weighted. See the notes below for further information. str
Default Value : None
on For a DataFrame, a datetime-like column on which to calculate the rolling window, rather than the DataFrame’s index. Provided integer column is ignored and excluded from result since an integer index is not used to calculate the rolling window. str
axis   int or str
Default Value : 0
closed  Make the interval closed on the ‘right’, ‘left’, ‘both’ or ‘neither’ endpoints. For offset-based windows, it defaults to ‘right’. For fixed windows, defaults to ‘both’. Remaining cases not implemented for fixed windows.
Default Value : None

Returns: a Window or Rolling sub-classed for the particular operation


Download the above Notebook from here.

Previous: Splitting the object in Pandas
Next: Expanding transformations in Pandas