Elementwise conversion
Applying a uniform scalar conversion to every cell in a small or irregular DataFrame.
Pandas · Module
DataFrame.applymap applies a scalar-to-scalar callable to every DataFrame element and returns a transformed DataFrame. It is deprecated; use DataFrame.map instead.
DataFrame.applymap applies a callable separately to every DataFrame element. The callable must accept one scalar and return one scalar; optional keyword arguments are forwarded to it, while na_action='ignore' preserves missing values without calling the function.
DataFrame.applymap(func, na_action=None, **kwargs)| Name | Type | Description |
|---|---|---|
func | callable | Callable receiving one DataFrame element and returning one value. |
na_action | {None, 'ignore'}, default None | Controls missing-value handling; 'ignore' propagates missing values without calling func. |
**kwargs | optional keyword arguments | Additional keyword arguments passed to func. |
DataFrame — transformed DataFrame.
import pandas as pd
df = pd.DataFrame({"a": [1, 2], "b": [3, 4]})
result = df.applymap(lambda value: value * 10)
print(result)Creates a new DataFrame by multiplying each cell value by 10.
Applying a uniform scalar conversion to every cell in a small or irregular DataFrame.
Skipping missing values while applying a scalar formatter or validator.
Maintaining older code temporarily while migrating to the current API.
It transforms every cell independently and returns a DataFrame. The callable receives one scalar and must return one scalar.
Follow-up: What should replace it in current pandas? Use DataFrame.map, which is the renamed elementwise DataFrame method.
na_action accepts None or 'ignore'. With 'ignore', missing values are propagated and are not passed to the callable.
Follow-up: Why can this matter? A callable that assumes a concrete value may otherwise receive a missing-value marker.
The method accepts additional keyword arguments through **kwargs and forwards them to the callable. This allows configuration without wrapping the callable in another function.
Follow-up: What performance alternative should be considered first? Use a vectorized pandas or NumPy operation when available.
DataFrame.mapDataFrame.apply