# 9.9:  Custom aggregation function (.groupby() and .pivot_table()).  Group rows by 'SalesRep' and
# apply a function to each group that sums up the 'SaleAmount' column.  (In other words, this
# replicates what .groupby().sum() does).

import pandas as pd

def price_sum(this_df):
    return this_df.SaleAmount.sum()

df = pd.read_excel("../sales-funnel.xlsx")

dfgb = df.groupby('SalesRep').apply(price_sum)

dfgb



def price_sum_series(series):
    return series.sum()

dfpt = pd.pivot_table(df, index='SalesRep',
                          values='SaleAmount',
                          aggfunc=price_sum_series)

dfpt

