applymap() / DataFrame.map() (Pandas)

DataFrame.map() applies a function to every individual element of an entire DataFrame, cell by cell. It replaces the old applymap() name, which was deprecated and removed in recent pandas.

Pandas

When you need element-wise logic across a whole frame — formatting every number, applying the same transform to every cell — df.map(func) is the tool. It differs from df.apply(func), which passes whole columns or rows to your function rather than single values.

Historically this method was called applymap to distinguish it from Series.map, but pandas unified the naming: the per-element method on a DataFrame is now simply map(), matching Series.map(). In modern pandas calling applymap raises an AttributeError, so use df.map().

Like apply, element-wise map loops in Python and is slow on large frames; prefer vectorized column operations when they exist and save map for genuinely cell-by-cell work.

Syntax

df.map(func, na_action=None)  # formerly df.applymap(func)

Examples

Python

import pandas as pd
df = pd.DataFrame({"a": [1, 2]})
print(df.map(lambda x: x * 2))

Output:

   a
0  2
1  4

Learn it in a lesson

See also

Back to the Dictionary