pandas.api.extensions.ExtensionArray.map#

ExtensionArray.map(mapper, na_action=None)[source]#

Map values using an input mapping or function.

A callable mapper is applied to each element of the array in turn; a dict or Series mapper is used as a lookup table. Subclasses may override this method with an implementation that avoids the elementwise loop or preserves their dtype.

Parameters:
mapperfunction, dict, or Series

Mapping correspondence.

na_action{None, ‘ignore’}, default None

If ‘ignore’, propagate NA values, without passing them to the mapping correspondence. If ‘ignore’ is not supported, a NotImplementedError should be raised.

Returns:
Union[ndarray, Index, ExtensionArray]

The output of the mapping function applied to the array. If the function returns a tuple with more than one element a MultiIndex will be returned.

See also

Series.map

Map values of a Series according to an input mapping or function.

Index.map

Map values using an input mapping or function.

Examples

>>> arr = pd.array([1, 2, pd.NA], dtype="Int64")
>>> arr.map(lambda x: x * 10, na_action="ignore")
<IntegerArray>
[10, 20, <NA>]
Length: 3, dtype: Int64