map(self, mapper)
Maps the values (their categories, not the codes) of the index to new categories. If the mapping correspondence is one-to-one the result is a ~pandas.CategoricalIndex
which has the same order property as the original, otherwise an ~pandas.Index
is returned.
If a :None:None:`dict`
or ~pandas.Series
is used any unmapped category is mapped to NaN
. Note that if this happens an ~pandas.Index
will be returned.
Mapping correspondence.
Mapped index.
Map values using input an input mapping or function.
Index.map
Apply a mapping correspondence on an :None:class:`~pandas.Index`
.
Series.apply
Apply more complex functions on a :None:class:`~pandas.Series`
.
Series.map
Apply a mapping correspondence on a :None:class:`~pandas.Series`
.
>>> idx = pd.CategoricalIndex(['a', 'b', 'c'])This example is valid syntax, but we were not able to check execution
... idx CategoricalIndex(['a', 'b', 'c'], categories=['a', 'b', 'c'], ordered=False, dtype='category')
>>> idx.map(lambda x: x.upper()) CategoricalIndex(['A', 'B', 'C'], categories=['A', 'B', 'C'], ordered=False, dtype='category')This example is valid syntax, but we were not able to check execution
>>> idx.map({'a': 'first', 'b': 'second', 'c': 'third'}) CategoricalIndex(['first', 'second', 'third'], categories=['first', 'second', 'third'], ordered=False, dtype='category')
If the mapping is one-to-one the ordering of the categories is preserved:
This example is valid syntax, but we were not able to check execution>>> idx = pd.CategoricalIndex(['a', 'b', 'c'], ordered=True)This example is valid syntax, but we were not able to check execution
... idx CategoricalIndex(['a', 'b', 'c'], categories=['a', 'b', 'c'], ordered=True, dtype='category')
>>> idx.map({'a': 3, 'b': 2, 'c': 1}) CategoricalIndex([3, 2, 1], categories=[3, 2, 1], ordered=True, dtype='category')
If the mapping is not one-to-one an ~pandas.Index
is returned:
>>> idx.map({'a': 'first', 'b': 'second', 'c': 'first'}) Index(['first', 'second', 'first'], dtype='object')
If a :None:None:`dict`
is used, all unmapped categories are mapped to NaN
and the result is an ~pandas.Index
:
>>> idx.map({'a': 'first', 'b': 'second'}) Index(['first', 'second', nan], dtype='object')See :
The following pages refer to to this document either explicitly or contain code examples using this.
pandas.core.arrays.categorical.Categorical.map
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them