-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: update the pandas.Series.map docstring #20450
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2831,8 +2831,11 @@ def unstack(self, level=-1, fill_value=None): | |
|
||
def map(self, arg, na_action=None): | ||
""" | ||
Map values of Series using input correspondence (a dict, Series, or | ||
function). | ||
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 :class:`pandas.Series`. | ||
|
||
Parameters | ||
---------- | ||
|
@@ -2850,7 +2853,7 @@ def map(self, arg, na_action=None): | |
Examples | ||
-------- | ||
|
||
Map inputs to outputs (both of type `Series`): | ||
Map inputs to outputs (both of type :class:`pandas.Series`): | ||
|
||
>>> x = pd.Series([1,2,3], index=['one', 'two', 'three']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing spaces after comma for PEP-8. |
||
>>> x | ||
|
@@ -2864,35 +2867,46 @@ def map(self, arg, na_action=None): | |
1 foo | ||
2 bar | ||
3 baz | ||
dtype: object | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think these examples would be clearer if instead of Also, I think it should be useful to show the behaviour of |
||
|
||
>>> x.map(y) | ||
one foo | ||
two bar | ||
three baz | ||
dtype: object | ||
|
||
Map a function to a :class:`pandas.Series`. | ||
|
||
If `arg` is a dictionary, return a new Series with values converted | ||
according to the dictionary's mapping: | ||
>>> x.map(lambda x: x**2) | ||
one 1 | ||
two 4 | ||
three 9 | ||
dtype: int64 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would start by the example using a function as a parameter, which I think it's a more common use than with a series. |
||
|
||
If ``arg`` is a dictionary, return a new :class:`pandas.Series` with | ||
values converted according to the dictionary's mapping: | ||
|
||
>>> z = {1: 'A', 2: 'B', 3: 'C'} | ||
|
||
>>> x.map(z) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As |
||
one A | ||
two B | ||
three C | ||
dtype: object | ||
|
||
Use na_action to control whether NA values are affected by the mapping | ||
function. | ||
Use ``na_action`` to control whether NA values are affected by the | ||
mapping function. | ||
|
||
>>> s = pd.Series([1, 2, 3, np.nan]) | ||
|
||
>>> s2 = s.map('this is a string {}'.format, na_action=None) | ||
>>> s.map('this is a string {}'.format, na_action=None) | ||
0 this is a string 1.0 | ||
1 this is a string 2.0 | ||
2 this is a string 3.0 | ||
3 this is a string nan | ||
dtype: object | ||
|
||
>>> s3 = s.map('this is a string {}'.format, na_action='ignore') | ||
>>> s.map('this is a string {}'.format, na_action='ignore') | ||
0 this is a string 1.0 | ||
1 this is a string 2.0 | ||
2 this is a string 3.0 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a
See Also
section? I think at leastapply
andapplymap
are related. May be the Pythonmap
built-in could be linked too?