pandas.Series.rolling

pandas 3.1.1 · Series and accessors · method

Build a moving window defined by an observation count, time span or custom indexer.

Call syntax

Series.rolling(…) Full signature
Series.rolling(
    window,
    min_periods=None,
    center=False,
    win_type=None,
    on=None,
    closed=None,
    step=None,
    method='single',
)

Run the example

Edit the example and select Run Python to see the result.

Parameters

ParameterRequirementAccepted values and behavior
window Required
Positional or keyword
int, timedelta, str, offset, or BaseIndexer subclass

Set the number of observations, time span, or custom indexer defining each window.

min_periods Optional
Positional or keyword
Default None
int

Require this many valid observations in a window before pandas reports a value.

center Optional
Positional or keyword
Default False
bool

Set each result's label to the center of its window where supported.

win_type Optional
Positional or keyword
Default None
str

Choose a SciPy window type for weighted rolling calculations.

on Optional
Positional or keyword
Default None
str

Choose the shared key columns or name the axis column used by the operation.

closed Optional
Positional or keyword
Default None
str

Choose which interval boundaries are included.

step Optional
Positional or keyword
Default None
int

Set how many positions to advance between successive selections or windows.

method Optional
Positional or keyword
Default 'single'
str {'single', 'table'}

Choose the algorithm used to calculate, align, or fill the result.

Returns

pandas.api.typing.Window or pandas.api.typing.Rolling