def map(self, mapper):
    "\n        Map categories using input correspondence (dict, Series, or function).\n\n        Maps the categories to new categories. If the mapping correspondence is\n        one-to-one the result is a :class:`~pandas.Categorical` which has the\n        same order property as the original, otherwise a :class:`~pandas.Index`\n        is returned.\n\n        If a `dict` or :class:`~pandas.Series` is used any unmapped category is\n        mapped to `NaN`. Note that if this happens an :class:`~pandas.Index`\n        will be returned.\n\n        Parameters\n        ----------\n        mapper : function, dict, or Series\n            Mapping correspondence.\n\n        Returns\n        -------\n        pandas.Categorical or pandas.Index\n            Mapped categorical.\n\n        See Also\n        --------\n        CategoricalIndex.map : Apply a mapping correspondence on a\n            :class:`~pandas.CategoricalIndex`.\n        Index.map : Apply a mapping correspondence on an\n            :class:`~pandas.Index`.\n        Series.map : Apply a mapping correspondence on a\n            :class:`~pandas.Series`.\n        Series.apply : Apply more complex functions on a\n            :class:`~pandas.Series`.\n\n        Examples\n        --------\n        >>> cat = pd.Categorical(['a', 'b', 'c'])\n        >>> cat\n        [a, b, c]\n        Categories (3, object): [a, b, c]\n        >>> cat.map(lambda x: x.upper())\n        [A, B, C]\n        Categories (3, object): [A, B, C]\n        >>> cat.map({'a': 'first', 'b': 'second', 'c': 'third'})\n        [first, second, third]\n        Categories (3, object): [first, second, third]\n\n        If the mapping is one-to-one the ordering of the categories is\n        preserved:\n\n        >>> cat = pd.Categorical(['a', 'b', 'c'], ordered=True)\n        >>> cat\n        [a, b, c]\n        Categories (3, object): [a < b < c]\n        >>> cat.map({'a': 3, 'b': 2, 'c': 1})\n        [3, 2, 1]\n        Categories (3, int64): [3 < 2 < 1]\n\n        If the mapping is not one-to-one an :class:`~pandas.Index` is returned:\n\n        >>> cat.map({'a': 'first', 'b': 'second', 'c': 'first'})\n        Index(['first', 'second', 'first'], dtype='object')\n\n        If a `dict` is used, all unmapped categories are mapped to `NaN` and\n        the result is an :class:`~pandas.Index`:\n\n        >>> cat.map({'a': 'first', 'b': 'second'})\n        Index(['first', 'second', nan], dtype='object')\n        "
    new_categories = self.categories.map(mapper)
    try:
        return self.from_codes(self._codes.copy(), categories=new_categories, ordered=self.ordered)
    except ValueError:
        return np.take(new_categories, self._codes)
Map categories using input correspondence (dict, Series, or function).

Maps the categories to new categories. If the mapping correspondence is
one-to-one the result is a :class:`~pandas.Categorical` which has the
same order property as the original, otherwise a :class:`~pandas.Index`
is returned.

If a `dict` or :class:`~pandas.Series` is used any unmapped category is
mapped to `NaN`. Note that if this happens an :class:`~pandas.Index`
will be returned.

Parameters
----------
mapper : function, dict, or Series
    Mapping correspondence.

Returns
-------
pandas.Categorical or pandas.Index
    Mapped categorical.

See Also
--------
CategoricalIndex.map : Apply a mapping correspondence on a
    :class:`~pandas.CategoricalIndex`.
Index.map : Apply a mapping correspondence on an
    :class:`~pandas.Index`.
Series.map : Apply a mapping correspondence on a
    :class:`~pandas.Series`.
Series.apply : Apply more complex functions on a
    :class:`~pandas.Series`.

Examples
--------
>>> cat = pd.Categorical(['a', 'b', 'c'])
>>> cat
[a, b, c]
Categories (3, object): [a, b, c]
>>> cat.map(lambda x: x.upper())
[A, B, C]
Categories (3, object): [A, B, C]
>>> cat.map({'a': 'first', 'b': 'second', 'c': 'third'})
[first, second, third]
Categories (3, object): [first, second, third]

If the mapping is one-to-one the ordering of the categories is
preserved:

>>> cat = pd.Categorical(['a', 'b', 'c'], ordered=True)
>>> cat
[a, b, c]
Categories (3, object): [a < b < c]
>>> cat.map({'a': 3, 'b': 2, 'c': 1})
[3, 2, 1]
Categories (3, int64): [3 < 2 < 1]

If the mapping is not one-to-one an :class:`~pandas.Index` is returned:

>>> cat.map({'a': 'first', 'b': 'second', 'c': 'first'})
Index(['first', 'second', 'first'], dtype='object')

If a `dict` is used, all unmapped categories are mapped to `NaN` and
the result is an :class:`~pandas.Index`:

>>> cat.map({'a': 'first', 'b': 'second'})
Index(['first', 'second', nan], dtype='object')
def map(self, mapper):
    "\n        Map categories using input correspondence (dict, Series, or function).\n\n        Maps the categories to new categories. If the mapping correspondence is\n        one-to-one the result is a :class:`~pandas.Categorical` which has the\n        same order property as the original, otherwise a :class:`~pandas.Index`\n        is returned.\n\n        If a `dict` or :class:`~pandas.Series` is used any unmapped category is\n        mapped to `NaN`. Note that if this happens an :class:`~pandas.Index`\n        will be returned.\n\n        Parameters\n        ----------\n        mapper : function, dict, or Series\n            Mapping correspondence.\n\n        Returns\n        -------\n        pandas.Categorical or pandas.Index\n            Mapped categorical.\n\n        See Also\n        --------\n        CategoricalIndex.map : Apply a mapping correspondence on a\n            :class:`~pandas.CategoricalIndex`.\n        Index.map : Apply a mapping correspondence on an\n            :class:`~pandas.Index`.\n        Series.map : Apply a mapping correspondence on a\n            :class:`~pandas.Series`.\n        Series.apply : Apply more complex functions on a\n            :class:`~pandas.Series`.\n\n        Examples\n        --------\n        >>> cat = pd.Categorical(['a', 'b', 'c'])\n        >>> cat\n        [a, b, c]\n        Categories (3, object): [a, b, c]\n        >>> cat.map(lambda x: x.upper())\n        [A, B, C]\n        Categories (3, object): [A, B, C]\n        >>> cat.map({'a': 'first', 'b': 'second', 'c': 'third'})\n        [first, second, third]\n        Categories (3, object): [first, second, third]\n\n        If the mapping is one-to-one the ordering of the categories is\n        preserved:\n\n        >>> cat = pd.Categorical(['a', 'b', 'c'], ordered=True)\n        >>> cat\n        [a, b, c]\n        Categories (3, object): [a < b < c]\n        >>> cat.map({'a': 3, 'b': 2, 'c': 1})\n        [3, 2, 1]\n        Categories (3, int64): [3 < 2 < 1]\n\n        If the mapping is not one-to-one an :class:`~pandas.Index` is returned:\n\n        >>> cat.map({'a': 'first', 'b': 'second', 'c': 'first'})\n        Index(['first', 'second', 'first'], dtype='object')\n\n        If a `dict` is used, all unmapped categories are mapped to `NaN` and\n        the result is an :class:`~pandas.Index`:\n\n        >>> cat.map({'a': 'first', 'b': 'second'})\n        Index(['first', 'second', nan], dtype='object')\n        "
    new_categories = self.categories.map(mapper)
    try:
        return self.from_codes(self._codes.copy(), categories=new_categories, ordered=self.ordered)
    except ValueError:
        return np.take(new_categories, self._codes)