bigframes.pandas.DataFrame.rolling#

DataFrame.rolling(window: int | Timedelta | timedelta64 | timedelta | str, min_periods=None, on: str | None = None, closed: Literal['right', 'left', 'both', 'neither'] = 'right') Window[source]#

Provide rolling window calculations.

Examples:

>>> import bigframes.pandas as bpd
>>> s = bpd.Series([0,1,2,3,4])
>>> s.rolling(window=3).min()
0    <NA>
1    <NA>
2       0
3       1
4       2
dtype: Int64
>>> df = bpd.DataFrame({'A': [0,1,2,3], 'B': [0,2,4,6]})
>>> df.rolling(window=2, on='A', closed='both').sum()
A     B
0  0  <NA>
1  1     2
2  2     6
3  3    12

[4 rows x 2 columns]
Parameters:
  • window (int, pandas.Timedelta, numpy.timedelta64, datetime.timedelta, str) –

    Size of the moving window.

    If an integer, the fixed number of observations used for each window.

    If a string, the timedelta representation in string. This string must be parsable by pandas.Timedelta().

    Otherwise, the time range for each window.

  • min_periods (int, default None) –

    Minimum number of observations in window required to have a value; otherwise, result is np.nan.

    For a window that is specified by an integer, min_periods will default to the size of the window.

    For a window that is not spicified by an interger, min_periods will default to 1.

  • on (str, optional) – For a DataFrame, a column label on which to calculate the rolling window, rather than the DataFrame’s index.

  • closed (str, default 'right') – If ‘right’, the first point in the window is excluded from calculations. If ‘left’, the last point in the window is excluded from calculations. If ‘both’, the no points in the window are excluded from calculations. If ‘neither’, the first and last points in the window are excluded from calculations.

Returns:

Window subclass if a win_type is passed.

Rolling subclass if win_type is not passed.

Return type:

bigframes.core.window.Window