Skip to content

Commit 5291f68

Browse files
manuelsManuel Schölling
authored and
Manuel Schölling
committed
Make Series.map() documentation a bit more verbose
1 parent 0c8442c commit 5291f68

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

pandas/core/series.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -2121,13 +2121,17 @@ def map(self, arg, na_action=None):
21212121
Examples
21222122
--------
21232123
2124-
Map inputs to outputs
2124+
>>> import pandas as pd
2125+
2126+
Map inputs to outputs (both of type `Series`)
21252127
2128+
>>> x = pd.Series([1,2,3], index=['one', 'two', 'three'])
21262129
>>> x
21272130
one 1
21282131
two 2
21292132
three 3
21302133
2134+
>>> y = pd.Series(['foo', 'bar', 'baz'], index=[1,2,3])
21312135
>>> y
21322136
1 foo
21332137
2 bar
@@ -2138,6 +2142,15 @@ def map(self, arg, na_action=None):
21382142
two bar
21392143
three baz
21402144
2145+
Mapping a dictionary keys on the index labels works similar as with a `Series`:
2146+
2147+
>>> z = {1: 'A', 2: 'B', 3: 'C'}
2148+
2149+
>>> x.map(z)
2150+
one A
2151+
two B
2152+
three C
2153+
21412154
Use na_action to control whether NA values are affected by the mapping
21422155
function.
21432156
@@ -2159,6 +2172,11 @@ def map(self, arg, na_action=None):
21592172
3 NaN
21602173
dtype: object
21612174
2175+
See also
2176+
--------
2177+
Series.apply: For applying more complex functions on a Series
2178+
DataFrame.apply: Apply a function row-/column-wise
2179+
DataFrame.applymap: Apply a function elementwise on a whole DataFrame
21622180
"""
21632181

21642182
if is_extension_type(self.dtype):

0 commit comments

Comments
 (0)