Skip to content

Commit c5113f2

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

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

pandas/core/series.py

+20-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,16 @@ 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
2146+
with a `Series`:
2147+
2148+
>>> z = {1: 'A', 2: 'B', 3: 'C'}
2149+
2150+
>>> x.map(z)
2151+
one A
2152+
two B
2153+
three C
2154+
21412155
Use na_action to control whether NA values are affected by the mapping
21422156
function.
21432157
@@ -2159,6 +2173,11 @@ def map(self, arg, na_action=None):
21592173
3 NaN
21602174
dtype: object
21612175
2176+
See also
2177+
--------
2178+
Series.apply: For applying more complex functions on a Series
2179+
DataFrame.apply: Apply a function row-/column-wise
2180+
DataFrame.applymap: Apply a function elementwise on a whole DataFrame
21622181
"""
21632182

21642183
if is_extension_type(self.dtype):

0 commit comments

Comments
 (0)