pandas.api.extensions.ExtensionArray._pad_or_backfill#
- ExtensionArray._pad_or_backfill(*, method, limit=None, limit_area=None, copy=True)[source]#
Pad or backfill values, used by Series/DataFrame ffill and bfill.
- Parameters:
- method{‘backfill’, ‘bfill’, ‘pad’, ‘ffill’}
Method to use for filling holes in reindexed Series:
pad / ffill: propagate last valid observation forward to next valid.
backfill / bfill: use NEXT valid observation to fill gap.
- limitint, default None
This is the maximum number of consecutive NaN values to forward/backward fill. 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.
- limit_area{‘inside’, ‘outside’} or None, default None
Specifies which area to limit filling. - ‘inside’: Limit the filling to the area within the gaps. - ‘outside’: Limit the filling to the area outside the gaps. If None, no limitation is applied.
- copybool, default True
Whether to make a copy of the data before filling. If False, then the original should be modified and no new memory should be allocated. For ExtensionArray subclasses that cannot do this, it is at the author’s discretion whether to ignore “copy=False” or to raise. The base class implementation ignores the keyword if any NAs are present.
- Returns:
- Same type as self
The filled array with the same type as the original.
See also
Series.ffill
Forward fill missing values.
Series.bfill
Backward fill missing values.
DataFrame.ffill
Forward fill missing values in DataFrame.
DataFrame.bfill
Backward fill missing values in DataFrame.
api.types.isna
Check for missing values.
api.types.isnull
Check for missing values.
Examples
>>> arr = pd.array([np.nan, np.nan, 2, 3, np.nan, np.nan]) >>> arr._pad_or_backfill(method="backfill", limit=1) <IntegerArray> [<NA>, 2, 2, 3, <NA>, <NA>] Length: 6, dtype: Int64