From 509c600a65102b0ca0e56de47a4ea494c0ea260f Mon Sep 17 00:00:00 2001 From: astrastefania Date: Mon, 12 Mar 2018 21:34:14 +0100 Subject: [PATCH 1/4] DOC: Improve the docstring of Series.add_suffix() --- pandas/core/generic.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index fa1632a5da6cc..4462c60caf6b9 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2978,15 +2978,37 @@ def add_prefix(self, prefix): def add_suffix(self, suffix): """ - Concatenate suffix string with panel items names. + Add a suffix string to panel items names. Parameters ---------- - suffix : string + suffix : str + The string to add after each item name. Returns ------- - with_suffix : type of caller + Series + Original Series with updated item names. + + See Also + -------- + pandas.Series.add_prefix: Concatenate prefix string with panel items names. + + Examples + -------- + >>> s = pd.Series([1,2,3,4]) + >>> s + 0 1 + 1 2 + 2 3 + 3 4 + dtype: int64 + >>> s.add_suffix('_item') + 0_item 1 + 1_item 2 + 2_item 3 + 3_item 4 + dtype: int64 """ new_data = self._data.add_suffix(suffix) return self._constructor(new_data).__finalize__(self) From e580e06dc856405e4b06861fc76ff28637ad341d Mon Sep 17 00:00:00 2001 From: astrastefania Date: Tue, 13 Mar 2018 11:15:40 +0100 Subject: [PATCH 2/4] DOC: Docstring fixed after the comments --- pandas/core/generic.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 4462c60caf6b9..cd7987ec126de 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2978,7 +2978,7 @@ def add_prefix(self, prefix): def add_suffix(self, suffix): """ - Add a suffix string to panel items names. + Add a suffix string to Series items names. Parameters ---------- @@ -2992,11 +2992,11 @@ def add_suffix(self, suffix): See Also -------- - pandas.Series.add_prefix: Concatenate prefix string with panel items names. + Series.add_prefix: Concatenate prefix string with Series items names. Examples -------- - >>> s = pd.Series([1,2,3,4]) + >>> s = pd.Series([1, 2, 3, 4]) >>> s 0 1 1 2 From b96a1b313c2639b120b4089f0680c745e3c18f74 Mon Sep 17 00:00:00 2001 From: astrastefania Date: Tue, 13 Mar 2018 18:20:38 +0100 Subject: [PATCH 3/4] DOC: Add DataFrame example --- pandas/core/generic.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index cd7987ec126de..f973b56c8b624 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2978,21 +2978,24 @@ def add_prefix(self, prefix): def add_suffix(self, suffix): """ - Add a suffix string to Series items names. + Suffix labels with string `suffix`. + + For Series, the row labels are suffixed. + For DataFrame, the column labels are suffixed. Parameters ---------- suffix : str - The string to add after each item name. + The string to add after each label. Returns ------- - Series - Original Series with updated item names. + Series or DataFrame + New Series or DataFrame with updated labels. See Also -------- - Series.add_prefix: Concatenate prefix string with Series items names. + Series.add_prefix: Prefix labels with string `prefix`. Examples -------- @@ -3009,6 +3012,20 @@ def add_suffix(self, suffix): 2_item 3 3_item 4 dtype: int64 + + >>> df = pd.DataFrame({'A': [1, 2, 3, 4], 'B': [3, 4, 5, 6]}) + >>> df + A B + 0 1 3 + 1 2 4 + 2 3 5 + 3 4 6 + >>> df.add_suffix('_col') + A_col B_col + 0 1 3 + 1 2 4 + 2 3 5 + 3 4 6 """ new_data = self._data.add_suffix(suffix) return self._constructor(new_data).__finalize__(self) From fdba3d4d406c4332f1865ca847155f9084ae47ad Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Tue, 13 Mar 2018 12:53:21 -0500 Subject: [PATCH 4/4] Fixups, DataFrame.add_* --- pandas/core/generic.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 34d9d011e516f..6a68fccb46eac 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2951,7 +2951,8 @@ def add_prefix(self, prefix): See Also -------- - Series.add_suffix: Suffix labels with string `suffix`. + Series.add_suffix: Suffix row labels with string `suffix`. + DataFrame.add_suffix: Suffix column labels with string `suffix`. Examples -------- @@ -3007,7 +3008,8 @@ def add_suffix(self, suffix): See Also -------- - Series.add_prefix: Prefix labels with string `prefix`. + Series.add_prefix: Prefix row labels with string `prefix`. + DataFrame.add_prefix: Prefix column labels with string `prefix`. Examples -------- @@ -3018,6 +3020,7 @@ def add_suffix(self, suffix): 2 3 3 4 dtype: int64 + >>> s.add_suffix('_item') 0_item 1 1_item 2 @@ -3032,8 +3035,9 @@ def add_suffix(self, suffix): 1 2 4 2 3 5 3 4 6 + >>> df.add_suffix('_col') - A_col B_col + A_col B_col 0 1 3 1 2 4 2 3 5