Series.map()

noun

say it: “SEER-eez dot MAP” /ˈsɪriz dɑt ˈmæp/

A pandas method that turns every value into the one a dictionary pairs with it, and marks as missing any value the dictionary doesn't list.

What does Series.map() do in pandas?

Series.map(), given a dictionary, gives each value the one the dictionary pairs with it. A value the dictionary doesn't name becomes NaN, so count the missing values afterward to catch a spelling you didn't list.

import pandas as pd
sizes = pd.Series(["small", "S", "sm", "XXL"])
print(sizes.map({"small": "S", "S": "S", "sm": "S"}))   # S, S, S, NaN

In a sentence

  • “After Series.map(), two sizes came out NaN, because the dictionary didn't list them.”
  • “Series.map() turned every spelling of small into S.”

Level: Journeyman · More Python terms at this level

Updated