From d71a944d25ddf75c5282d61ac90a309676d14597 Mon Sep 17 00:00:00 2001 From: Krishna Date: Mon, 22 Oct 2018 18:04:34 +0100 Subject: [PATCH 1/7] Added a Multi Index example for the Series.sum method --- pandas/core/generic.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 31b700abcfdb3..addfc54d6d1cd 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10166,6 +10166,37 @@ def _doc_parms(cls): _sum_examples = """\ Examples -------- +``MultiIndex`` series example of monthly rainfall + +>>> index = [np.tile(['London', 'New York'], 3), +... np.repeat(['Jun', 'Jul', 'Aug'], 2)] +>>> s = pd.Series([47, 112, 35, 117, 54, 113], index=index) +>>> s.rename_axis(['city', 'month'], inplace=True) +>>> s +city month +London Jun 47 +New York Jun 112 +London Jul 35 +New York Jul 117 +London Aug 54 +New York Aug 113 +dtype: int64 + +>>> s.sum() +478 + +>>> s.sum(level='city') +London 136 +New York 342 +dtype: int64 + +>>> s.sum(level=1) +month +Jun 159 +Jul 152 +Aug 167 +dtype: int64 + By default, the sum of an empty or all-NA Series is ``0``. >>> pd.Series([]).sum() # min_count=0 is the default From 89c29774853631f29eaed3c1603f139432556530 Mon Sep 17 00:00:00 2001 From: Krishna Date: Mon, 22 Oct 2018 18:16:03 +0100 Subject: [PATCH 2/7] Added description before method call. --- 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 addfc54d6d1cd..8478483584a55 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10185,11 +10185,12 @@ def _doc_parms(cls): >>> s.sum() 478 +Sum using level names, as well as indices + >>> s.sum(level='city') London 136 New York 342 dtype: int64 - >>> s.sum(level=1) month Jun 159 From 91fad75c0b9c99a15adf0dc6a6cd1e0247bdc1b1 Mon Sep 17 00:00:00 2001 From: Krishna Date: Mon, 22 Oct 2018 18:22:37 +0100 Subject: [PATCH 3/7] Added line break for formatting. --- pandas/core/generic.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 8478483584a55..95b510b3cf638 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10191,6 +10191,7 @@ def _doc_parms(cls): London 136 New York 342 dtype: int64 + >>> s.sum(level=1) month Jun 159 From 3a5f9fe552fef36a651adc687bb12fd4feba5902 Mon Sep 17 00:00:00 2001 From: Krishna Date: Tue, 23 Oct 2018 16:22:49 +0100 Subject: [PATCH 4/7] DOC: corrected output. --- pandas/core/generic.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 95b510b3cf638..137ec26705986 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10188,6 +10188,7 @@ def _doc_parms(cls): Sum using level names, as well as indices >>> s.sum(level='city') +city London 136 New York 342 dtype: int64 From 56c034012090a75980a25354c7147027a94dfbf6 Mon Sep 17 00:00:00 2001 From: Krishna Date: Thu, 25 Oct 2018 15:09:08 +0100 Subject: [PATCH 5/7] DOC: Restructured indexing as requested. --- pandas/core/generic.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index ab998c0dc302c..778f92f204e13 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10187,10 +10187,11 @@ def _doc_parms(cls): -------- ``MultiIndex`` series example of monthly rainfall ->>> index = [np.tile(['London', 'New York'], 3), -... np.repeat(['Jun', 'Jul', 'Aug'], 2)] +>>> index = pd.MultiIndex.from_arrays( +... [np.tile(['London', 'New York'], 3), +... np.repeat(['Jun', 'Jul', 'Aug'], 2)], +... names=['city', 'month']) >>> s = pd.Series([47, 112, 35, 117, 54, 113], index=index) ->>> s.rename_axis(['city', 'month'], inplace=True) >>> s city month London Jun 47 From 920526b2f6e248917f613eb7738cdd6cd9265797 Mon Sep 17 00:00:00 2001 From: Krishna Date: Thu, 25 Oct 2018 15:50:12 +0100 Subject: [PATCH 6/7] DOC: Switched from MultiIndex.from_arrays to MultiIndex.from_product --- pandas/core/generic.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 778f92f204e13..e337f0f86964a 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10187,19 +10187,18 @@ def _doc_parms(cls): -------- ``MultiIndex`` series example of monthly rainfall ->>> index = pd.MultiIndex.from_arrays( -... [np.tile(['London', 'New York'], 3), -... np.repeat(['Jun', 'Jul', 'Aug'], 2)], -... names=['city', 'month']) ->>> s = pd.Series([47, 112, 35, 117, 54, 113], index=index) +>>> index = pd.MultiIndex.from_product( +... [['London', 'New York'], ['Jun', 'Jul', 'Aug']], +... names=['city', 'month']) +>>> s = pd.Series([47, 35, 54, 112, 117, 113], index=index) >>> s city month London Jun 47 + Jul 35 + Aug 54 New York Jun 112 -London Jul 35 -New York Jul 117 -London Aug 54 -New York Aug 113 + Jul 117 + Aug 113 dtype: int64 >>> s.sum() From d3e07bfe1345cdb536af36d63fc0ebc2f3135198 Mon Sep 17 00:00:00 2001 From: Krishna Date: Thu, 25 Oct 2018 16:46:07 +0100 Subject: [PATCH 7/7] DOC: Reformatting indents --- pandas/core/generic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index e337f0f86964a..e273fd020a011 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10188,8 +10188,8 @@ def _doc_parms(cls): ``MultiIndex`` series example of monthly rainfall >>> index = pd.MultiIndex.from_product( -... [['London', 'New York'], ['Jun', 'Jul', 'Aug']], -... names=['city', 'month']) +... [['London', 'New York'], ['Jun', 'Jul', 'Aug']], +... names=['city', 'month']) >>> s = pd.Series([47, 35, 54, 112, 117, 113], index=index) >>> s city month