groupby

PHOTO EMBED

Fri Jan 07 2022 12:18:54 GMT+0000 (Coordinated Universal Time)

Saved by @CaoimhedeFrein #python

create new column use transform: get the count of distributor_id for each seg

df.groupby(["seg_met"]).distributorid.transform("count")

just to get the counts use: 
df['distributorid'].groupby([df.seg_met]).agg(['count'])

#these do the same thing! 
pred_table.groupby('seg_met')['predicted_sales'].sum()
pred_table['predicted_sales'].groupby(pred_table.seg_met).sum()


# produces Pandas Series
data.groupby('month')['duration'].sum() 
# Produces Pandas DataFrame
data.groupby('month')[['duration']].sum()
content_copyCOPY