# 9.11:  Custom 'grouping' function (.groupby() only).  Pass a function to groupby() that identifies
# 2 groups using the 'Product' column:  if the value is 'CPU' or 'Monitor', return 'hardware';
# otherwise, return 'software'.  Count the number of rows in each group with .count().

import pandas as pd

def grouper(row_idx):
    row = df.loc[row_idx]
    if row['Product'] in ['Software', 'Maintenance']:
        return 'software'
    else:
        return 'hardware'

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

df.groupby(grouper).Account.count()

# The function receives a row index which you can use with .loc[] to find the row being grouped.
# Have the function return 'Software' if the 'Product' value is 'Software' or 'Maintenance', and
# 'Hardware' if the Product is 'CPU'.
# 
# .pivot_table() does not offer a way to customize groupings, however you can precompute a grouping
# key for each row in the DataFrame and then pivot on that.

