Calculate the rolling count of non NaN observations.
Include only float, int, boolean columns.
Added in version 1.5.0.
Return type is the same as the original object with np.float64 dtype.
See also
pandas.Series.rollingCalling rolling with Series data.
pandas.DataFrame.rollingCalling rolling with DataFrames.
pandas.Series.countAggregating count for Series.
pandas.DataFrame.countAggregating count for DataFrame.
Examples
>>> s = pd.Series([2, 3, np.nan, 10])
>>> s.rolling(2).count()
0 NaN
1 2.0
2 1.0
3 1.0
dtype: float64
>>> s.rolling(3).count()
0 NaN
1 NaN
2 2.0
3 2.0
dtype: float64
>>> s.rolling(4).count()
0 NaN
1 NaN
2 NaN
3 3.0
dtype: float64
© 2008–2011, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
© 2011–2025, Open source contributors
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/2.3.0/reference/api/pandas.core.window.rolling.Rolling.count.html