Skip to content

DOC: Added a Multi Index example for the Series.sum method #23279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Oct 25, 2018
34 changes: 34 additions & 0 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10166,6 +10166,40 @@ 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

Sum using level names, as well as indices

>>> s.sum(level='city')
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
Expand Down