import pandas as pd
values = [['2017-01-15', 'Tim', 4],
['2016-06-17', 'Tim', 3],
['2018-04-02', 'Tim', 2],
['2017-01-15', 'Sue', 4],
['2016-06-17', 'Sue', 3],
['2018-04-02', 'Sue', 2],
['2017-01-15', 'Eric', 4],
['2016-06-17', 'Eric', 3],
['2018-04-02', 'Betty', 2],
['2017-01-15', 'Betty', 4],
['2016-06-17', 'Betty', 3],
['2018-01-02', 'Betty', 2]]
df = pd.DataFrame(values)
# Convert first column to datetime
df[0] = df[0].astype('datetime64[ns]')
# Set first two columns as index
df = df.set_index([0, 1])
# Group by Year
df.groupby(pd.Grouper(level=0, freq='Y')).sum()
# Group by Person
df.groupby(pd.Grouper(level=1)).sum()
# Group by Year, Person
df.groupby(pd.Grouper(level=0, freq='Y'), pd.Grouper(level=1)).sum()
# ValueError: No axis named Grouper(level=1, axis=0, sort=False) for object type <class 'pandas.core.frame.DataFrame'>