Using the groupby() and reduce() functions