Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Pandas · Module

df.applymap

DataFrame.applymap applies a scalar-to-scalar callable to every DataFrame element and returns a transformed DataFrame. It is deprecated; use DataFrame.map instead.

How it works

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.

Syntax

DataFrame.applymap(func, na_action=None, **kwargs)

Parameters

NameTypeDescription
funccallableCallable receiving one DataFrame element and returning one value.
na_action{None, 'ignore'}, default NoneControls missing-value handling; 'ignore' propagates missing values without calling func.
**kwargsoptional keyword argumentsAdditional keyword arguments passed to func.

Returns

DataFrame — transformed DataFrame.

Key points

  • The callable runs independently for each cell rather than along rows or columns.
  • func must map one scalar input to one scalar output.
  • Keyword arguments supplied to applymap are forwarded to func.
  • The method is deprecated in current pandas documentation.
  • DataFrame.map is the documented replacement for applymap.

Common mistakes

  • This method is deprecated; use DataFrame.map for new code.
  • With na_action='ignore', missing values pass through unchanged and are not given to the callable.
  • Prefer a vectorized operation when one exists because elementwise Python calls can be slower.

Example: Elementwise transformation

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.

When to use it

Elementwise conversion

Applying a uniform scalar conversion to every cell in a small or irregular DataFrame.

Missing-value-aware processing

Skipping missing values while applying a scalar formatter or validator.

Compatibility migration

Maintaining older code temporarily while migrating to the current API.

Interview questions

QWhat does DataFrame.applymap do?

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.

QHow does na_action affect missing values?

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.

QHow are extra arguments passed, and what performance concern applies?

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.map
  • DataFrame.apply

Source: pandas.DataFrame.applymap#. Checked 2026-10-15.