import numpy as np
import pandas as pd
np.random.seed(0)
df = pd.DataFrame({'state': ['CA', 'WA', 'CO', 'AZ'] * 3, 'office_id': list
    (range(1, 7)) * 2, 'sales': [np.random.randint(100000, 999999) for _ in
    range(12)]})
state_office = df.groupby(['state', 'office_id']).agg({'sales': 'sum'})
state_pcts = state_office.groupby(level=0).apply(lambda x: 100 * x / float(
    x.sum()))
Процент Pandas от общего количества с groupby