Group by Several Keys
Multi-level grouping and the result index.
Group on More Than One Column
Pass a list of keys to groupby and pandas forms a group for every unique combination of those columns.
df.groupby(["city", "year"])Every Combo Is a Group
Two cities and three years can yield up to six groups, one per existing combination found in your data.