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()
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter