Python/🐼 Pandas for Data Analysis/GroupBy & Aggregation

GroupBy & Aggregation

GroupBy splits data into groups, applies a function, and combines results. Common aggregations: sum(), mean(), count(), max(), min().

Guided Example

import pandas as pd

df = pd.DataFrame({
    "dept": ["Sales", "Sales", "IT", "IT"],
    "salary": [50000, 60000, 70000, 80000]
})
print(df.groupby("dept")["salary"].mean())

Practice Problems (0/3 solved)

Medium

Group and Sum

Group sales data by category and print the total revenue per category.

Loading Python...
Loading...

Loading Python runtime (Pyodide)...

Medium

Multiple Aggregations

Group by department and calculate both mean and max salary. Print the result.

Loading Python...
Loading...

Loading Python runtime (Pyodide)...

Hard

Top N Per Group

Find the highest-paid employee in each department. Print department and salary.

Loading Python...
Loading...

Loading Python runtime (Pyodide)...