dailylog 7-28-20

less than 1 minute read

df = og_df_new.copy()

def make_pivot_table_for_graphs(df, _x, _y):
    df[_y] = df[_y].astype('category')
#     tempcol = df.columns[-2]
    df1 = df.groupby([_x,_y])[_y].count().rename('count').reset_index()
    df2 = dict(df1.groupby(_x)['count'].sum())
    df1['total'] = df1.apply(lambda x: df2[x[_x]], axis=1)
    df1['percent'] = df1['count']/df1['total']
    print(df1)

make_pivot_table_for_graphs(df, 'executive_leader', 'ipf_binned')