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

Pandas · Module

df.reindex

Reindex a DataFrame to specified row and/or column labels, optionally filling newly introduced gaps. Missing labels become NaN by default or receive a supplied fill value.

How it works

DataFrame.reindex creates a DataFrame aligned to requested row and/or column labels. Existing labels are reordered, absent labels are added with missing values or a chosen fill value, and optional methods can fill gaps when the index supports them.

Syntax

DataFrame.reindex(*labels=None, **, index=None, columns=None, axis=None, method=None, copy=<no_default>, level=None, fill_value=nan, limit=None, tolerance=None)

Parameters

NameTypeDescription
labelsarray-like, optionalTarget labels for the selected axis.
indexarray-like, optionalTarget row labels.
columnsarray-like, optionalTarget column labels.
axisint or str, optionalAxis to reindex: 'index', 'columns', 0, or 1.
method{None, 'backfill'/'bfill', 'pad'/'ffill', 'nearest'}Gap-filling strategy: None, backfill/bfill, pad/ffill, or nearest.
copybool or no_defaultWhether to copy data; the current stable API uses a no-default sentinel.
levelint or level name, optionalBroadcast target labels across a level for a MultiIndex.
fill_valuescalar, default NaNValue used for newly introduced labels.
limitint, optionalMaximum consecutive labels to fill.
tolerancescalar or list-like, optionalMaximum distance for inexact matching.

Returns

DataFrame with changed index.

Key points

  • Use reindex to align a DataFrame with a newly specified index and optional gap-filling rules.
  • New labels without matching source labels receive missing values by default.
  • labels supplies target labels for the axis selected by axis.
  • index explicitly supplies replacement row labels.
  • columns explicitly supplies replacement column labels.
  • axis accepts either a named axis or its numeric position.

Common mistakes

  • The copy argument is transitional because copy-on-write changes its behavior in pandas 3.0.

Example: Reindex rows and fill missing labels

import pandas as pd

frame = pd.DataFrame({"value": [10, 20]}, index=["a", "b"])
result = frame.reindex(index=["b", "c"], fill_value=0)
print(result)

Reorders the existing row and adds the missing row with the specified fill value.

When to use it

Data alignment

Align rows from multiple tables before arithmetic or concatenation.

Schema normalization

Ensure a DataFrame has a required row or column schema.

Ordered-series completion

Create regularly ordered labels and fill gaps from nearby observations.

Interview questions

QWhat does DataFrame.reindex do when a requested label is absent?

It conforms a DataFrame to requested labels on one or both axes. Existing labels are reordered, while labels absent from the original index receive missing values unless filling is requested.

Follow-up: How would you add columns rather than rows? Pass the desired labels with the columns parameter, or target the columns axis through labels and axis.

QWhat are the two supported calling conventions?

Use index and columns for explicit axis selection, or labels with axis for the alternate calling convention. The method returns a DataFrame with the changed index or columns.

Follow-up: Why prefer index and columns in production code? They make the target axis explicit and allow both axes to be changed in one call.

QHow do method, limit, and tolerance affect reindexing?

method controls filling of holes and accepts None, backfill/bfill, pad/ffill, or nearest. It is intended for ordered indexes; limit and tolerance further restrict filling behavior.

Follow-up: When is tolerance useful? It limits how far a nearest-style match may search, with scalar or per-element values supported by the documented API.

  • DataFrame.reindex_like
  • Series.reindex

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