File tree Expand file tree Collapse file tree 2 files changed +16
-10
lines changed Expand file tree Collapse file tree 2 files changed +16
-10
lines changed Original file line number Diff line number Diff line change @@ -1551,11 +1551,6 @@ def map(
15511551 Series.apply : Apply more complex functions on a
15521552 :class:`~pandas.Series`.
15531553
1554- Notes
1555- -----
1556- The mapping function is applied to the categories, not to
1557- each element of the array.
1558-
15591554 Examples
15601555 --------
15611556 >>> cat = pd.Categorical(["a", "b", "c"])
@@ -1590,6 +1585,21 @@ def map(
15901585
15911586 >>> cat.map({"a": "first", "b": "second"}, na_action=None)
15921587 Index(['first', 'second', nan], dtype='str')
1588+
1589+ The mapping function is applied to categories, not to each value. It is
1590+ therefore only called once per unique category, and the result reused for
1591+ all occurrences:
1592+
1593+ >>> cat = pd.Categorical(["a", "a", "b"]) # doctest: +SKIP
1594+ >>> calls = [] # doctest: +SKIP
1595+ >>> def f(x): # doctest: +SKIP
1596+ ... calls.append(x)
1597+ ... return x.upper()
1598+ >>> cat.map(f)
1599+ ['A', 'A', 'B']
1600+ Categories (2, str): ['A', 'B']
1601+ >>> calls # doctest: +SKIP
1602+ ['a', 'b']
15931603 """
15941604 assert callable (mapper ) or is_dict_like (mapper )
15951605
Original file line number Diff line number Diff line change @@ -4389,11 +4389,7 @@ def map(
43894389 provides a method for default values), then this default is used
43904390 rather than ``NaN``.
43914391
4392- When the Series has ``dtype="category"``, the function is applied
4393- to the categories and not to each individual value. This means
4394- that if the same category appears multiple times, the function is
4395- only called once for that category, and the result is reused for
4396- all occurrences. Missing values (NaN) are not passed to the function.
4392+
43974393
43984394 Examples
43994395 --------
You can’t perform that action at this time.
0 commit comments