Python: apply(), map(), and applymap() for Data Manipulation

Rahul S
2 min readSep 21, 2023
  • apply() works on both DataFrames and Series, allowing custom functions for transformation.
  • map() is specifically for Series objects and is useful for value replacement or mapping.
  • applymap() is applied to all elements in a DataFrame and is handy for element-wise operations.

apply()

apply() is a Pandas DataFrame and Series method that allows us to apply a function to alter values along a specified axis (default is axis=0 for columns).

  • Usage: Apply a function to alter values along an axis in a DataFrame or Series.

Syntax:

  • DataFrame.apply(func, axis=0): Apply func along columns (default).
  • Series.apply(func): Apply func element-wise.

map()

map() is a Pandas Series method that substitutes each value in a Series using either a function, dictionary, or another Series. It works only on Series objects.

  • Usage: Substitute each value in a Series using a function, dictionary, or another Series (works on Series objects only).

--

--