MCPcopy
hub / github.com/pandas-dev/pandas / bfill

Method bfill

pandas/core/generic.py:7263–7373  ·  view source on GitHub ↗

Fill NA/NaN values by using the next valid observation to fill the gap. This method fills missing values in a backward direction along the specified axis, propagating non-null values from later positions to earlier positions containing NaN. Parameters

(
        self,
        *,
        axis: None | Axis = None,
        inplace: bool = False,
        limit: None | int = None,
        limit_area: Literal["inside", "outside"] | None = None,
    )

Source from the content-addressed store, hash-verified

7261
7262 @final
7263 def bfill(
7264 self,
7265 *,
7266 axis: None | Axis = None,
7267 inplace: bool = False,
7268 limit: None | int = None,
7269 limit_area: Literal["inside", "outside"] | None = None,
7270 ) -> Self:
7271 """
7272 Fill NA/NaN values by using the next valid observation to fill the gap.
7273
7274 This method fills missing values in a backward direction along the
7275 specified axis, propagating non-null values from later positions to
7276 earlier positions containing NaN.
7277
7278 Parameters
7279 ----------
7280 axis : {0 or 'index'} for Series, {0 or 'index', 1 or 'columns'} for DataFrame
7281 Axis along which to fill missing values. For `Series`
7282 this parameter is unused and defaults to 0.
7283 inplace : bool, default False
7284 If True, fill in-place. Note: this will modify any
7285 other views on this object (e.g., a no-copy slice for a column in a
7286 DataFrame).
7287 limit : int, default None
7288 If method is specified, this is the maximum number of consecutive
7289 NaN values to forward/backward fill. In other words, if there is
7290 a gap with more than this number of consecutive NaNs, it will only
7291 be partially filled. If method is not specified, this is the
7292 maximum number of entries along the entire axis where NaNs will be
7293 filled. Must be greater than 0 if not None.
7294 limit_area : {`None`, 'inside', 'outside'}, default None
7295 If limit is specified, consecutive NaNs will be filled with this
7296 restriction.
7297
7298 * ``None``: No fill restriction.
7299 * 'inside': Only fill NaNs surrounded by valid values
7300 (interpolate).
7301 * 'outside': Only fill NaNs outside valid values (extrapolate).
7302
7303 .. versionadded:: 2.2.0
7304
7305 Returns
7306 -------
7307 Series/DataFrame
7308 Object with missing values filled.
7309
7310 See Also
7311 --------
7312 DataFrame.ffill : Fill NA/NaN values by propagating the last valid
7313 observation to next valid.
7314
7315 Examples
7316 --------
7317 For Series:
7318
7319 >>> s = pd.Series([1, None, None, 2])
7320 >>> s.bfill()

Callers 15

time_bfillMethod · 0.45
time_bfillMethod · 0.45
time_df_bfillMethod · 0.45
time_srs_bfillMethod · 0.45
test_fillna_2dMethod · 0.45
test_reindex_downcastingFunction · 0.45
test_fillna_natMethod · 0.45
test_fillnaMethod · 0.45
test_timedelta_fillnaMethod · 0.45

Calls 2

_pad_or_backfillMethod · 0.95
validate_bool_kwargFunction · 0.90

Tested by 15

test_fillna_2dMethod · 0.36
test_reindex_downcastingFunction · 0.36
test_fillna_natMethod · 0.36
test_fillnaMethod · 0.36
test_timedelta_fillnaMethod · 0.36
test_fillna_bugMethod · 0.36