Skip to content

Make Series.map() documentation a bit more verbose #15235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2121,13 +2121,17 @@ def map(self, arg, na_action=None):
Examples
--------

Map inputs to outputs
>>> import pandas as pd

Map inputs to outputs (both of type `Series`)

>>> x = pd.Series([1,2,3], index=['one', 'two', 'three'])
>>> x
one 1
two 2
three 3

>>> y = pd.Series(['foo', 'bar', 'baz'], index=[1,2,3])
>>> y
1 foo
2 bar
Expand All @@ -2138,6 +2142,16 @@ def map(self, arg, na_action=None):
two bar
three baz

Mapping a dictionary keys on the index labels works similar as
with a `Series`:

>>> z = {1: 'A', 2: 'B', 3: 'C'}

>>> x.map(z)
one A
two B
three C

Use na_action to control whether NA values are affected by the mapping
function.

Expand All @@ -2159,6 +2173,11 @@ def map(self, arg, na_action=None):
3 NaN
dtype: object

See also
--------
Series.apply: For applying more complex functions on a Series
DataFrame.apply: Apply a function row-/column-wise
DataFrame.applymap: Apply a function elementwise on a whole DataFrame
"""

if is_extension_type(self.dtype):
Expand Down