turicreate.SArray.rolling_count

SArray.rolling_count(window_start, window_end)

Count the number of non-NULL values of different subsets over this SArray.

The subset that the count is executed on is defined as an inclusive range relative to the position to each value in the SArray, using window_start and window_end. For a better understanding of this, see the examples below.

Parameters:
window_start : int

The start of the subset to count relative to the current value.

window_end : int

The end of the subset to count relative to the current value. Must be greater than window_start.

Returns:
out : SArray

Examples

>>> import pandas
>>> sa = SArray([1,2,3,None,5])
>>> series = pandas.Series([1,2,3,None,5])

A rolling count with a window including the previous 2 entries including the current: >>> sa.rolling_count(-2,0) dtype: int Rows: 5 [1, 2, 3, 2, 2]

Pandas equivalent: >>> pandas.rolling_count(series, 3) 0 1 1 2 2 3 3 2 4 2 dtype: float64

A rolling count with a size of 3, centered around the current: >>> sa.rolling_count(-1,1) dtype: int Rows: 5 [2, 3, 2, 2, 1]

Pandas equivalent: >>> pandas.rolling_count(series, 3, center=True) 0 2 1 3 2 2 3 2 4 1 dtype: float64

A rolling count with a window including the current and the 2 entries following: >>> sa.rolling_count(0,2) dtype: int Rows: 5 [3, 2, 2, 1, 1]

A rolling count with a window including the previous 2 entries NOT including the current: >>> sa.rolling_count(-2,-1) dtype: int Rows: 5 [0, 1, 2, 2, 1]