0
0
Pandasdata~30 mins

Data aggregation reporting in Pandas - Mini Project: Build & Apply

Choose your learning style9 modes available
Data Aggregation Reporting
📖 Scenario: You work in a small retail store. You have sales data for different products sold over several days. You want to find out the total sales for each product to understand which products sell the most.
🎯 Goal: Create a program that uses pandas to aggregate sales data by product and report the total sales for each product.
📋 What You'll Learn
Create a pandas DataFrame with sales data for products and their sales amounts.
Create a variable to hold the column name to group by.
Use pandas aggregation to sum sales for each product.
Print the aggregated total sales per product.
💡 Why This Matters
🌍 Real World
Retail stores and businesses often need to summarize sales data to understand product performance and make decisions.
💼 Career
Data aggregation is a fundamental skill for data analysts and data scientists to prepare reports and insights from raw data.
Progress0 / 4 steps
1
Create the sales data DataFrame
Create a pandas DataFrame called sales_data with two columns: 'Product' and 'Sales'. Use these exact rows: 'Apple', 10, 'Banana', 15, 'Apple', 5, 'Orange', 8, 'Banana', 7.
Pandas
Need a hint?

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

2
Set the grouping column
Create a variable called group_column and set it to the string 'Product' to specify the column to group by.
Pandas
Need a hint?

Just assign the string 'Product' to the variable group_column.

3
Aggregate total sales by product
Create a new DataFrame called total_sales by grouping sales_data using group_column and summing the 'Sales' values for each product.
Pandas
Need a hint?

Use groupby() on sales_data with group_column, then select 'Sales' and apply sum().

4
Print the total sales report
Print the total_sales DataFrame to display the total sales for each product.
Pandas
Need a hint?

Use print(total_sales) to show the result.