Examples
import numpy as np
import pandas as pd
idx = pd.MultiIndex.from_arrays([
['warm', 'warm', 'cold', 'cold'],
['cat', 'eagle', 'snake', 'spider']],
names=['blooded', 'animal'])
s = pd.Series([4, 2, 0, 8], name='legs', index=idx)
s
s.sum()
Sum using level names, as well as indices:
s.sum(level='blooded')
s.sum(level=0)
By default, the sum of an empty or all-NA Series is 0.
pd.Series([]).sum() # min_count=0 is the default
pd.Series([]).sum(min_count=1)
pd.Series([np.nan]).sum()
pd.Series([np.nan]).sum(min_count=1)