GroupBy splits data into groups, applies a function, and combines results. Common aggregations: sum(), mean(), count(), max(), min().
import pandas as pd
df = pd.DataFrame({
"dept": ["Sales", "Sales", "IT", "IT"],
"salary": [50000, 60000, 70000, 80000]
})
print(df.groupby("dept")["salary"].mean())Group sales data by category and print the total revenue per category.
Loading Python runtime (Pyodide)...
Group by department and calculate both mean and max salary. Print the result.
Loading Python runtime (Pyodide)...
Find the highest-paid employee in each department. Print department and salary.
Loading Python runtime (Pyodide)...