w3resource

Pandas Series: rolling() function

Rolling window calculations in Pandas

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

Syntax:

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

Parameters:

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
Required
center Set the labels at the center of the window. bool
Default Value : False
Required
win_type Provide a window type. If None, all points are evenly weighted. See the notes below for further information. str
Default Value : None
Required
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
Optional
axis   int or str
Default Value : 0
Required
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.
str
Default Value : None
Required

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

Example:


Download the above Notebook from here.



Inviting useful, relevant, well-written and unique guest posts