pyspark.pandas.window.Rolling.count

Rolling.count() → FrameLike[source]

The rolling count of any non-NaN observations inside the window.

Note

the current implementation of this API uses Spark’s Window without specifying partition specification. This leads to move all data into single partition in single machine and could cause serious performance degradation. Avoid this method against very large dataset.

Returns
Series or DataFrame

Return type is the same as the original object with np.float64 dtype.

See also

pyspark.pandas.Series.expanding

Calling object with Series data.

pyspark.pandas.DataFrame.expanding

Calling object with DataFrames.

pyspark.pandas.Series.count

Count of the full Series.

pyspark.pandas.DataFrame.count

Count of the full DataFrame.

Examples

>>> s = ps.Series([2, 3, float("nan"), 10])
>>> s.rolling(1).count()
0    1.0
1    1.0
2    0.0
3    1.0
dtype: float64
>>> s.rolling(3).count()
0    1.0
1    2.0
2    2.0
3    2.0
dtype: float64
>>> s.to_frame().rolling(1).count()
     0
0  1.0
1  1.0
2  0.0
3  1.0
>>> s.to_frame().rolling(3).count()
     0
0  1.0
1  2.0
2  2.0
3  2.0