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

Pandas · Function

df.fillna

Replaces missing values in a DataFrame with a scalar or aligned, column-specific values. It returns a filled copy by default, or can modify the original in place.

How it works

Call fillna on a DataFrame with a scalar or aligned values to replace missing entries. By default it returns the filled DataFrame; use inplace=True to modify the existing object, and limit can cap how many missing entries are filled along an axis.

Syntax

DataFrame.fillna(*value*, ***, *axis=None*, *inplace=False*, *limit=None*)

Parameters

NameTypeDescription
valuescalar, dict, Series, or DataFrameScalar, dictionary, Series, or DataFrame used to replace missing values; mappings or aligned objects can specify values by column.
axis{0 or 'index', 1 or 'columns'}, default NoneAxis along which values are filled; DataFrames accept 0 or index, and 1 or columns.
inplacebool, default FalseWhether to modify the DataFrame in place.
limitint, default NoneMaximum number of entries along the entire axis to fill; must be positive when provided.

Returns

DataFrame or None. A filled DataFrame is returned unless inplace=True, in which case the operation returns None.

Key points

  • The method replaces NA or NaN entries with a supplied replacement.
  • A scalar replacement applies the same fill value wherever a missing entry is found.
  • Mappings and aligned pandas objects can provide distinct replacement values by column.
  • For a DataFrame, axis may select the index direction or the columns direction.
  • Setting inplace=True changes the existing DataFrame instead of producing the normal separate result.
  • limit bounds the number of entries filled across the chosen axis.

Common mistakes

  • If limit is supplied, it must be a positive integer.
  • The axis setting does not affect a Series and defaults to zero there.

Example: Fill selected columns with mappings

import pandas as pd

df = pd.DataFrame({
    "score": [10, None, 30],
    "team": ["A", "B", None],
})

filled = df.fillna({"score": 0, "team": "unknown"})
print(filled)

Fills each column's missing entries with a column-specific value.

When to use it

Impute a common numeric default

A numeric feature has absent observations and downstream calculations require a defined fallback.

Apply per-column defaults

Different columns need semantically appropriate replacements, such as zero for counts and a label for categories.

Bound the fill operation

A cleanup job must avoid filling more than a controlled number of missing cells.

Interview questions

QWhat does DataFrame.fillna do, and what kinds of values can it accept?

It replaces missing values with the supplied value. The value may be a scalar or aligned mapping-like object such as a dictionary, Series, or DataFrame.

Follow-up: How would you fill different columns differently? Pass a dictionary whose keys are column names and whose values are the respective replacements.

QWhat is the effect of the inplace parameter?

With inplace=False, the operation returns a filled DataFrame and leaves the original unchanged. With inplace=True, it fills the existing object in place.

Follow-up: What should code do when it needs both the original and filled versions? Keep the default and assign the returned DataFrame to a new variable.

QHow does limit constrain filling?

limit sets the maximum number of entries along the entire selected axis where missing values are filled. It defaults to None, meaning no such cap is applied.

Follow-up: What validation applies to limit? A supplied limit must be greater than zero.

  • pandas.DataFrame.isna
  • pandas.DataFrame.dropna
  • pandas.Series.fillna
  • pandas.DataFrame.replace

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