w3resource

Pandas: Series - map() function

Map values of Pandas Series

The map() function is used to map values of Series according to input correspondence.

Used for substituting each value in a Series with another value, that may be derived from a function, a dict or a Series.

Syntax:

Series.map(self, arg, na_action=None)
Pandas Series map image

Parameters:

Name Description Type/Default Value Required / Optional
arg Mapping correspondence. function, dict, or Series Required
na_action If ‘ignore’, propagate NaN values, without passing them to the mapping correspondence. {None, ‘ignore’}
Default Value : None
Required

Returns: Series
Same index as caller.

Notes: When arg is a dictionary, values in Series that are not in the dictionary (as keys) are converted to NaN. However, if the dictionary is a dict subclass that defines __missing__ (i.e. provides a method for default values), then this default is used rather than NaN.

Example:


Download the above Notebook from here.



Inviting useful, relevant, well-written and unique guest posts