What does replace() do and how does it differ from fillna() or map()?

Quick Overview

Asks what the pandas replace() method does and how it compares with fillna() and map() when cleaning a column. Tests whether you know how each method treats unmatched and missing values, and when each one is the right tool for a data cleaning task.

What does replace() do and how does it differ from fillna() or map()?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

What does `replace()` do in pandas, and how does it differ from `fillna()` or `map()`? ```hint Follow the values nobody mentioned Run each method on a column with a mapping that covers only some of its values. Look at what happens to the values the mapping leaves out, and to the missing ones. ``` ### What a Strong Answer Covers - What `replace()` matches and what it does with values it does not match - Which values `fillna()` acts on and the kinds of fill it supports - How `map()` treats values absent from the mapping, and where it is available - When to pick each method for a given cleaning task - At least one pitfall, such as substring matching or a dtype change ### Follow-up Questions - How would you turn every empty or whitespace-only string in a DataFrame into NaN? - Why can `map()` with a dict turn an integer-coded column into floats? - How would you fill the missing values in each numeric column with that column's median? - How do you limit a `replace()` call to a single column of a DataFrame?

Overview: Asks what the pandas replace() method does and how it compares with fillna() and map() when cleaning a column. Tests whether you know how each method treats unmatched and missing values, and when each one is the right tool for a data cleaning task.

Nov 25, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

What does replace() do in pandas, and how does it differ from fillna() or map()?

What a Strong Answer Covers Guidance

  • What replace() matches and what it does with values it does not match
  • Which values fillna() acts on and the kinds of fill it supports
  • How map() treats values absent from the mapping, and where it is available
  • When to pick each method for a given cleaning task
  • At least one pitfall, such as substring matching or a dtype change

Follow-up Questions Guidance

  • How would you turn every empty or whitespace-only string in a DataFrame into NaN?
  • Why can map() with a dict turn an integer-coded column into floats?
  • How would you fill the missing values in each numeric column with that column's median?
  • How do you limit a replace() call to a single column of a DataFrame?