Fill NA/NaN values using the specified method within groups.
Deprecated since version 2.2.0: This method is deprecated and will be removed in a future version. Use the SeriesGroupBy.ffill() or SeriesGroupBy.bfill() for forward or backward filling instead. If you want to fill with a single value, use Series.fillna() instead.
Value to use to fill holes (e.g. 0), alternately a dict/Series/DataFrame of values specifying which value to use for each index (for a Series) or column (for a DataFrame). Values not in the dict/Series/DataFrame will not be filled. This value cannot be a list. Users wanting to use the value argument and not method should prefer Series.fillna() as this will produce the same result and be more performant.
Method to use for filling holes. 'ffill' will propagate the last valid observation forward within a group. 'bfill' will use next valid observation to fill the gap.
Unused, only for compatibility with DataFrameGroupBy.fillna().
Broken. Do not set to True.
If method is specified, this is the maximum number of consecutive NaN values to forward/backward fill within a group. In other words, if there is a gap with more than this number of consecutive NaNs, it will only be partially filled. If method is not specified, this is the maximum number of entries along the entire axis where NaNs will be filled. Must be greater than 0 if not None.
A dict of item->dtype of what to downcast if possible, or the string ‘infer’ which will try to downcast to an appropriate equal type (e.g. float64 to int64 if possible).
Object with missing values filled within groups.
Examples
For SeriesGroupBy:
>>> lst = ['cat', 'cat', 'cat', 'mouse', 'mouse']
>>> ser = pd.Series([1, None, None, 2, None], index=lst)
>>> ser
cat 1.0
cat NaN
cat NaN
mouse 2.0
mouse NaN
dtype: float64
>>> ser.groupby(level=0).fillna(0, limit=1)
cat 1.0
cat 0.0
cat NaN
mouse 2.0
mouse 0.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.groupby.SeriesGroupBy.fillna.html