From c5113f2a15220c1935cbdf293eb89819a151e739 Mon Sep 17 00:00:00 2001 From: manuels Date: Thu, 26 Jan 2017 09:23:28 +0100 Subject: [PATCH] Make Series.map() documentation a bit more verbose --- pandas/core/series.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 9845e1cd4ad47..45297bec5c3f9 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2121,13 +2121,17 @@ def map(self, arg, na_action=None): Examples -------- - Map inputs to outputs + >>> import pandas as pd + + Map inputs to outputs (both of type `Series`) + >>> x = pd.Series([1,2,3], index=['one', 'two', 'three']) >>> x one 1 two 2 three 3 + >>> y = pd.Series(['foo', 'bar', 'baz'], index=[1,2,3]) >>> y 1 foo 2 bar @@ -2138,6 +2142,16 @@ def map(self, arg, na_action=None): two bar three baz + Mapping a dictionary keys on the index labels works similar as + with a `Series`: + + >>> z = {1: 'A', 2: 'B', 3: 'C'} + + >>> x.map(z) + one A + two B + three C + Use na_action to control whether NA values are affected by the mapping function. @@ -2159,6 +2173,11 @@ def map(self, arg, na_action=None): 3 NaN dtype: object + See also + -------- + Series.apply: For applying more complex functions on a Series + DataFrame.apply: Apply a function row-/column-wise + DataFrame.applymap: Apply a function elementwise on a whole DataFrame """ if is_extension_type(self.dtype):