fillna()

noun

say it: “FIL en-AY” /ˈfɪl ˌɛnˈeɪ/

A pandas method that replaces each missing value with a value you choose, such as a word or an average.

What does fillna() do in pandas?

fillna() puts a stand-in into every missing value of a column or table, such as "Unknown" for a missing name or the median for a missing number, and hands back the result. A filled value wasn't measured, so it's good practice to flag which ones were filled.

import pandas as pd
intake = pd.read_csv("intake.csv", na_values=["unknown", "-"])
intake["name"] = intake["name"].fillna("Unknown")
intake["age_years"] = intake["age_years"].fillna(intake["age_years"].median())

In a sentence

  • “She used fillna() with the median to fill in the missing ages.”
  • “fillna() put 'Unknown' in place of every missing name.”

Level: Journeyman · More Python terms at this level

Updated