pandas.api.typing.Rolling.count#
- Rolling.count(numeric_only=False)[source]#
Calculate the rolling count of non NaN observations.
This is useful for identifying windows with missing data, as it counts only non-NaN entries within each window.
- Parameters:
- numeric_onlybool, default False
Include only float, int, boolean columns.
- Returns:
- Series or DataFrame
Return type is the same as the original object with
np.float64dtype.
See also
Series.rollingCalling rolling with Series data.
DataFrame.rollingCalling rolling with DataFrames.
Series.countAggregating count for Series.
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