Skip to content

Commit e596cbf

Browse files
shawnheidejorisvandenbossche
authored andcommitted
DOC: added example to Series.map showing use of na_action parameter (GH14231)
DOC: closes #14231, refines parameter description and adds additional example to Series.map that shows use of na_action parameter.
1 parent 5e2f9da commit e596cbf

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

pandas/core/series.py

+31-5
Original file line numberDiff line numberDiff line change
@@ -2099,10 +2099,19 @@ def map(self, arg, na_action=None):
20992099
----------
21002100
arg : function, dict, or Series
21012101
na_action : {None, 'ignore'}
2102-
If 'ignore', propagate NA values
2102+
If 'ignore', propagate NA values, without passing them to the
2103+
mapping function
2104+
2105+
Returns
2106+
-------
2107+
y : Series
2108+
same index as caller
21032109
21042110
Examples
21052111
--------
2112+
2113+
Map inputs to outputs
2114+
21062115
>>> x
21072116
one 1
21082117
two 2
@@ -2118,10 +2127,27 @@ def map(self, arg, na_action=None):
21182127
two bar
21192128
three baz
21202129
2121-
Returns
2122-
-------
2123-
y : Series
2124-
same index as caller
2130+
Use na_action to control whether NA values are affected by the mapping
2131+
function.
2132+
2133+
>>> s = pd.Series([1, 2, 3, np.nan])
2134+
2135+
>>> s2 = s.map(lambda x: 'this is a string {}'.format(x),
2136+
na_action=None)
2137+
0 this is a string 1.0
2138+
1 this is a string 2.0
2139+
2 this is a string 3.0
2140+
3 this is a string nan
2141+
dtype: object
2142+
2143+
>>> s3 = s.map(lambda x: 'this is a string {}'.format(x),
2144+
na_action='ignore')
2145+
0 this is a string 1.0
2146+
1 this is a string 2.0
2147+
2 this is a string 3.0
2148+
3 NaN
2149+
dtype: object
2150+
21252151
"""
21262152

21272153
if is_extension_type(self.dtype):

0 commit comments

Comments
 (0)