-
-
Notifications
You must be signed in to change notification settings - Fork 19.1k
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']) | ||
|
||
>>> x | ||
|
@@ -2864,35 +2867,46 @@ def map(self, arg, na_action=None): | |
1 foo | ||
2 bar | ||
3 baz | ||
dtype: object | ||
|
||
|
||
>>> 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 | ||
|
||
|
||
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) | ||
|
||
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?