Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Pandas · Module

df.bfill

DataFrame.bfill fills missing values by propagating the next valid observation backward along an axis. It can limit the number and position of values filled, or modify the DataFrame in place.

How it works

DataFrame.bfill replaces missing values by propagating the next non-missing observation backward along the selected axis. It returns a filled DataFrame unless inplace=True, in which case it modifies the object and returns None.

Syntax

DataFrame.bfill(*, axis=None, inplace=False, limit=None, limit_area=None)

Parameters

NameTypeDescription
axis{0 or 'index', 1 or 'columns'}, default NoneAxis along which to fill missing values: 0 or 'index', or 1 or 'columns'.
inplacebool, default FalseWhether to modify the DataFrame in place.
limitint, default NoneMaximum number of consecutive missing values to fill; must be greater than zero when provided.
limit_area{None, 'inside', 'outside'}, default NoneRestricts filling to all positions, missing values inside valid values, or missing values outside valid values; requires limit.

Returns

DataFrame or None. The filled DataFrame is returned unless inplace=True, which returns None.

Key points

  • Use bfill when missing entries should inherit values from later observations rather than earlier ones.
  • The axis argument determines whether filling proceeds down rows or across columns.
  • Set inplace=True to mutate the existing DataFrame instead of receiving a separate result.
  • limit_area applies an inside or outside positional restriction, but only when limit is provided.
  • limit_area='outside' targets missing values beyond the valid observations at the ends.

Common mistakes

  • Using inplace=True can also change other views that reference the same DataFrame, such as a no-copy column slice.
  • When limit is supplied, it must be a positive integer.
  • With limit_area='inside', only missing values between valid observations are eligible for filling.

Example: Backward-fill limited gaps

import pandas as pd

frame = pd.DataFrame({"a": [1, None, None, 4], "b": [None, 2, None, 3]})
filled = frame.bfill(limit=1)
print(filled)

Creates a DataFrame and fills at most one consecutive missing value per gap using the next valid value.

When to use it

Fill short time-series gaps

A time-ordered table has short gaps, and later observations are the appropriate values to propagate backward.

Fill interior gaps

Only interior missing runs should be completed while edge gaps remain missing.

Update in place

A pipeline requires controlled mutation of an existing DataFrame object.

Interview questions

QWhat does DataFrame.bfill do?

It performs backward filling: each missing value can receive the next valid observation later along the selected axis. By default, it operates on the index axis for a DataFrame.

Follow-up: How would you prevent leading or trailing gaps from being filled? Set limit_area='inside' while also specifying limit.

QHow does limit affect bfill?

limit restricts how many consecutive missing entries are filled. A gap longer than the limit is only partially filled, and a non-None limit must be greater than zero.

Follow-up: How can you fill only missing values outside the valid-data region? Use limit_area='outside' with a specified limit.

QWhat does bfill return?

The method returns a DataFrame containing the filled values when inplace=False. With inplace=True, it modifies the original object and returns None.

Follow-up: What alias-related concern follows from inplace=True? Other views, including no-copy column slices, may observe the mutation.

  • DataFrame.ffill
  • DataFrame.fillna
  • Series.bfill
  • DataFrame.interpolate

Source: pandas.DataFrame.bfill. Checked 2026-10-15.