Python Group and Aggregate
groupby + meanPractice

Average sales per category

Split rows into groups, then reduce each group with mean(). Press Run to watch the buckets fill.

Picture this: split, then average

Same category goes in one bucket. Then take the mean.

rowscat + sales
→
groupby('cat')buckets
→
.mean()one number

In easy words

This is an Excel pivot: group by a column, then summarize another column.

Where this is used

Revenue by product line, average score by class, tickets by status.

Run algorithm

Each step highlights the matching Python line. Program output appears only when a line that prints actually runs.

Ready
catsales
A100
A120
B90
1import pandas as pd
2df = pd.DataFrame({"cat": ["A","A","B"], "sales": [100,120,90]})
3print(df.groupby("cat")["sales"].mean())
Output:

Example Program

1import pandas as pd
2df = pd.DataFrame({"cat": ["A","A","B"], "sales": [100,120,90]})
3print(df.groupby("cat")["sales"].mean())