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

Pandas · Module

df.interpolate

Fill missing DataFrame values by interpolation along an axis. The method supports controls for interpolation strategy, gap size, direction, region, and in-place updates.

How it works

DataFrame.interpolate fills missing values by estimating them from neighboring observations along the selected axis. Choose a method such as linear or time, and optionally constrain how many consecutive missing values are filled, which direction is used, or whether only interior or exterior gaps qualify.

Syntax

DataFrame.interpolate(*method='linear', axis=0, limit=None, inplace=False, limit_direction=None, limit_area=None, **kwargs)

Parameters

NameTypeDescription
methodstr, default 'linear'Interpolation strategy, such as linear, time, index, values, polynomial, or spline.
axis0 or 'index', 1 or 'columns', None, default 0Axis along which to interpolate: 0/'index' or 1/'columns'.
limitint, optionalMaximum number of consecutive NaNs to fill; must be greater than zero.
limit_direction'forward', 'backward', or 'both', optionalDirection for filling consecutive NaNs: forward, backward, or both.
limit_area'inside' or 'outside', optionalRestrict filling to interior or exterior NaN regions.
inplacebool, default FalseModify the DataFrame in place when possible.
**kwargsdictAdditional keyword arguments passed to the interpolation implementation; for example, order for polynomial or spline.

Returns

DataFrame or None. A new interpolated DataFrame is returned unless inplace=True, in which case the method returns None.

Key points

  • The method estimates replacements for missing values rather than simply copying a neighboring value.
  • Linear interpolation disregards index spacing and assumes observations are evenly spaced.
  • Time interpolation uses elapsed time between observations and is intended for daily or finer-grained data.
  • limit caps the number of adjacent missing entries filled within a gap.
  • limit_direction selects forward, backward, or bidirectional filling.
  • inplace requests modification of the existing DataFrame instead of returning a separately updated object.

Common mistakes

  • For a DataFrame or Series with a MultiIndex, use only the linear method.
  • Polynomial and spline interpolation require an integer order supplied through kwargs.
  • When provided, limit must be a positive integer.

Example: Fill bounded gaps

import pandas as pd

values = pd.DataFrame({"temperature": [10.0, None, None, 16.0]})
filled = values.interpolate(limit=1)
print(filled)

Interpolates one missing value in each consecutive gap, leaving any additional values in a longer gap unchanged.

When to use it

Estimate interior numeric gaps

A numeric column contains occasional missing measurements between valid readings.

Interpolate time-indexed data

Observations are indexed by dates and missing periods should reflect elapsed time.

Bound gap filling

Only short runs of missing values should be repaired while larger gaps remain visible.

Modify data in place

A pipeline needs to update an existing DataFrame without assigning the result.

Interview questions

QWhat does DataFrame.interpolate do?

It fills NaN values along the chosen axis using an interpolation method. The default method is linear, and the default axis is 0.

Follow-up: How would you restrict filling to a maximum gap length? Pass a positive limit; larger consecutive gaps are only partially filled according to limit_direction.

QHow do linear and index interpolation differ?

method='linear' treats values as equally spaced and ignores the index. method='index' uses the numerical index values when calculating the line.

Follow-up: Which method is suitable for a time-indexed DataFrame? Use method='time' for daily or higher-resolution data when the interval between observations should determine the interpolation.

QHow can the direction and location of filling be controlled?

limit_direction controls whether consecutive missing values are filled forward, backward, or in both directions. It defaults to forward.

Follow-up: How can endpoint behavior be constrained? Use limit_area='inside' to fill only NaNs surrounded by valid values, or 'outside' to fill extrapolated endpoint gaps.

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

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