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

Pandas · Module

df.ffill

DataFrame.ffill fills missing values by carrying the preceding valid observation forward along an axis. Optional limits control how many values or which regions are filled.

How it works

DataFrame.ffill scans along the selected axis and carries the most recent non-missing value into later missing positions. Use limit to bound filling, and limit_area to restrict it to interior gaps or values outside the observed range; with inplace=True, the method returns None and mutates the frame.

Syntax

DataFrame.ffill(*, axis=None, inplace=False, limit=None, limit_area=None, downcast=<no_default>)

Parameters

NameTypeDescription
axisint or {"index", "columns"}, default NoneAxis to fill: 0 or "index" for Series; 0/"index" or 1/"columns" for DataFrame.
inplacebool, default FalseWhether to modify the object directly.
limitint, default NoneMaximum number of consecutive missing values to fill; must be greater than zero when provided.
limit_area{None, "inside", "outside"}, default NoneRestriction for filling when limit is set: None, "inside", or "outside".
downcastdict or "infer", default <no_default>Mapping of items to dtypes for possible downcasting, or "infer"; the documentation marks this parameter as deprecated.

Returns

Series/DataFrame or None: the object with missing values filled, or None when inplace=True.

Key points

  • Forward filling copies the latest observed non-missing value into subsequent missing cells.
  • axis chooses whether propagation proceeds down the index or across DataFrame columns.
  • Set inplace=True to mutate the existing object instead of receiving a new filled object.
  • limit caps how many adjacent missing values are filled in each run.
  • limit_area changes which missing regions are eligible when a limit is present.
  • The result is a filled Series/DataFrame, or None for in-place operation.

Common mistakes

  • With inplace=True, other views sharing the object can also observe the mutation.
  • A supplied limit must be a positive integer.
  • limit_area="outside" fills edge gaps rather than gaps enclosed by valid values.

Example: Forward-fill a bounded gap

import pandas as pd

frame = pd.DataFrame({"temperature": [20.0, None, None, 23.0, None]})
filled = frame.ffill(limit=1)
print(filled)

Fills each missing run from its preceding value, but replaces at most one consecutive missing entry per run.

When to use it

Carry recent measurements forward

A time-ordered measurement table has short missing runs between observations.

Limit imputation across gaps

A bounded carry-forward is required so long gaps remain visibly missing.

Fill interior gaps only

Only holes enclosed by observations should be completed.

Propagate values horizontally

A row-wise record contains values spread across ordered columns.

Interview questions

QWhat does DataFrame.ffill do, and what does it return?

It propagates the last valid observation forward across missing values along the chosen axis. By default it returns a filled DataFrame; with inplace=True, it returns None.

Follow-up: How can filling be bounded? Set limit to the maximum number of consecutive missing entries to fill in a run.

QHow does axis affect forward filling?

For a DataFrame, axis=0 or "index" fills down rows within each column, while axis=1 or "columns" fills across columns within each row. The default axis is index-oriented.

Follow-up: What happens for a Series? Its axis parameter is unused and defaults to 0.

QWhat is the purpose of limit_area?

limit_area="inside" fills only missing values surrounded by valid values, while "outside" targets missing values outside valid values. This restriction applies when limit is specified.

Follow-up: How would you fill only interior gaps while limiting each gap to two entries? Use ffill(limit=2, limit_area="inside").

  • pandas.DataFrame.bfill
  • pandas.DataFrame.fillna
  • pandas.Series.ffill

Source: pandas.DataFrame.ffill#. Checked 2026-10-15.