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.


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


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

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.


Download the above Notebook from here.

Previous: Call function on self producing a Series in Pandas
Next: Splitting the object in Pandas