From 5e780e9805e8a7abb85a798c2401b946fcccd3df Mon Sep 17 00:00:00 2001 From: astrastefania Date: Mon, 12 Mar 2018 21:12:59 +0100 Subject: [PATCH 1/8] DOC: Improve the docstring of Series.add_prefix() --- pandas/core/generic.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 23654613104ec..95bab840f3d90 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2967,11 +2967,33 @@ def add_prefix(self, prefix): Parameters ---------- - prefix : string + prefix : str + The string to add before each item name. Returns ------- - with_prefix : type of caller + Series + Original Series with updated item names. + + See Also + -------- + pandas.Series.add_suffix: Add a suffix string to panel items names. + + Examples + -------- + >>> s = pd.Series([1,2,3,4]) + >>> s + 0 1 + 1 2 + 2 3 + 3 4 + dtype: int64 + >>> s.add_prefix('item_') + item_0 1 + item_1 2 + item_2 3 + item_3 4 + dtype: int64 """ new_data = self._data.add_prefix(prefix) return self._constructor(new_data).__finalize__(self) From 397f05d35ebec989d4c780776f329e80848b4e59 Mon Sep 17 00:00:00 2001 From: astrastefania Date: Tue, 13 Mar 2018 09:49:51 +0100 Subject: [PATCH 2/8] DOC: Fixe the issues in 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 95bab840f3d90..e5c38b47abca7 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2963,7 +2963,7 @@ def _update_inplace(self, result, verify_is_copy=True): def add_prefix(self, prefix): """ - Concatenate prefix string with panel items names. + Concatenate prefix string with Series items names. Parameters ---------- @@ -2977,11 +2977,11 @@ def add_prefix(self, prefix): See Also -------- - pandas.Series.add_suffix: Add a suffix string to panel items names. + Series.add_suffix: Add a suffix string to panel items names. Examples -------- - >>> s = pd.Series([1,2,3,4]) + >>> s = pd.Series([1, 2, 3, 4]) >>> s 0 1 1 2 From c719d7a3c4b04a0b46257a671b6b44361663b663 Mon Sep 17 00:00:00 2001 From: astrastefania Date: Tue, 13 Mar 2018 11:21:03 +0100 Subject: [PATCH 3/8] DOC: Update panle to Series --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index e5c38b47abca7..91a859612b690 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2977,7 +2977,7 @@ def add_prefix(self, prefix): See Also -------- - Series.add_suffix: Add a suffix string to panel items names. + Series.add_suffix: Add a suffix string to Series items names. Examples -------- From e14315d8cbff67f7a80e36d78878ce52aae38935 Mon Sep 17 00:00:00 2001 From: astrastefania Date: Tue, 13 Mar 2018 17:31:40 +0100 Subject: [PATCH 4/8] DOC: Added DataFrame example --- pandas/core/generic.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 91a859612b690..4c790d4d98f98 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2963,21 +2963,23 @@ def _update_inplace(self, result, verify_is_copy=True): def add_prefix(self, prefix): """ - Concatenate prefix string with Series items names. + Prefix labels with string `prefix`. + + For Series, the row labels are prefixed. For DataFrame, the column labels are prefixed. Parameters ---------- prefix : str - The string to add before each item name. + The string to add before each label. Returns ------- - Series - Original Series with updated item names. + Series or DataFrame + Original Series or DataFrame with updated labels. See Also -------- - Series.add_suffix: Add a suffix string to Series items names. + Series.add_suffix: Suffix labels with string `suffix`. Examples -------- @@ -2994,6 +2996,20 @@ def add_prefix(self, prefix): item_2 3 item_3 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('_item') + A_item B_item + 0 1 3 + 1 2 4 + 2 3 5 + 3 4 6 """ new_data = self._data.add_prefix(prefix) return self._constructor(new_data).__finalize__(self) From f23e3402bb7e8a0aeec52ec27de5453f0567fd54 Mon Sep 17 00:00:00 2001 From: astrastefania Date: Tue, 13 Mar 2018 17:33:52 +0100 Subject: [PATCH 5/8] DOC: Fix PEP8 --- pandas/core/generic.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 4c790d4d98f98..21a64d7846bae 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2965,7 +2965,8 @@ def add_prefix(self, prefix): """ Prefix labels with string `prefix`. - For Series, the row labels are prefixed. For DataFrame, the column labels are prefixed. + For Series, the row labels are prefixed. + For DataFrame, the column labels are prefixed. Parameters ---------- From 177285d5b6129a53f61290e8167c18e14396bd3c Mon Sep 17 00:00:00 2001 From: astrastefania Date: Tue, 13 Mar 2018 17:35:06 +0100 Subject: [PATCH 6/8] DOC: Fix PEP8spaces --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 21a64d7846bae..cf9eea8a22799 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2965,7 +2965,7 @@ def add_prefix(self, prefix): """ Prefix labels with string `prefix`. - For Series, the row labels are prefixed. + For Series, the row labels are prefixed. For DataFrame, the column labels are prefixed. Parameters From 67c8dbeba7cdc106d65c5cb65e917116c1170249 Mon Sep 17 00:00:00 2001 From: astrastefania Date: Tue, 13 Mar 2018 17:58:49 +0100 Subject: [PATCH 7/8] DOC: Fix last docstring issue --- 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 cf9eea8a22799..fcf4e26f5075c 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2976,7 +2976,7 @@ def add_prefix(self, prefix): Returns ------- Series or DataFrame - Original Series or DataFrame with updated labels. + New Series or DataFrame with updated labels. See Also -------- @@ -3005,8 +3005,8 @@ def add_prefix(self, prefix): 1 2 4 2 3 5 3 4 6 - >>> df.add_suffix('_item') - A_item B_item + >>> df.add_prefix('col_') + col_A col_B 0 1 3 1 2 4 2 3 5 From 6d599adf81cc6fea7a8068e9edfe89abefa60c0b Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Tue, 13 Mar 2018 12:50:06 -0500 Subject: [PATCH 8/8] Spacing --- pandas/core/generic.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index fcf4e26f5075c..64787869ef46c 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2991,6 +2991,7 @@ def add_prefix(self, prefix): 2 3 3 4 dtype: int64 + >>> s.add_prefix('item_') item_0 1 item_1 2 @@ -3005,8 +3006,9 @@ def add_prefix(self, prefix): 1 2 4 2 3 5 3 4 6 + >>> df.add_prefix('col_') - col_A col_B + col_A col_B 0 1 3 1 2 4 2 3 5