Pandas DataFrame: rolling() function
DataFrame - rolling() function
The rolling() function is used to provide rolling window calculations.
Syntax:
DataFrame.rolling(self, window, min_periods=None, center=False, win_type=None, on=None, axis=0, closed=None)
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. This is new in 0.19.0 |
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 Pandas DataFrame Notebooks from here.
Previous: DataFrame - groupby() function
Next: DataFrame - expanding() function
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/pandas/dataframe/dataframe-rolling.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics