0
0
Pandasdata~30 mins

Multiple aggregation functions in Pandas - Mini Project: Build & Apply

Choose your learning style9 modes available
Using Multiple Aggregation Functions with pandas
📖 Scenario: You work in a small store and have a list of sales data for different products. You want to learn how to find useful summary information like the total sales, average sales, and the highest sale for each product.
🎯 Goal: Build a pandas DataFrame with sales data, then use multiple aggregation functions to find the total, average, and maximum sales for each product.
📋 What You'll Learn
Create a pandas DataFrame with product sales data
Create a list of aggregation functions
Use the agg() method with multiple aggregation functions on grouped data
Print the final aggregated DataFrame
💡 Why This Matters
🌍 Real World
Stores and businesses often need to summarize sales data to understand performance by product or category.
💼 Career
Data analysts and scientists use grouping and aggregation to prepare reports and find insights from data.
Progress0 / 4 steps
1
Create the sales data DataFrame
Import pandas as pd and create a DataFrame called sales_data with these exact columns and rows:
Product: 'Apple', 'Banana', 'Apple', 'Banana', 'Apple'
Sales: 10, 15, 7, 20, 5
Pandas
Need a hint?

Use pd.DataFrame with a dictionary where keys are column names and values are lists of data.

2
Create a list of aggregation functions
Create a list called agg_functions that contains the strings 'sum', 'mean', and 'max' to use for aggregation.
Pandas
Need a hint?

Make a list with the exact strings 'sum', 'mean', and 'max'.

3
Group by product and apply multiple aggregation functions
Use sales_data.groupby('Product')['Sales'].agg(agg_functions) and save the result in a variable called summary.
Pandas
Need a hint?

Use groupby('Product') on sales_data, select the 'Sales' column, then call agg(agg_functions).

4
Print the aggregated summary
Print the variable summary to display the total, average, and maximum sales for each product.
Pandas
Need a hint?

Use print(summary) to show the results.