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,
)
| 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() |