Why groupby summarizes data by category
📖 Scenario: Imagine you run a small store. You have a list of sales with the product name and the amount sold. You want to find out how much money you made from each product category.
🎯 Goal: You will create a dictionary of sales data, set a category filter, use a loop to sum sales by category, and finally print the total sales per category.
📋 What You'll Learn
Create a dictionary called
sales with product names as keys and sales amounts as valuesCreate a variable called
category to select a product categoryUse a
for loop with variables product and amount to iterate over sales.items()Sum the sales amounts only for products in the selected category
Print the total sales amount for the selected category
💡 Why This Matters
🌍 Real World
Stores and businesses often need to see total sales by product category to understand which groups sell best.
💼 Career
Data analysts use grouping and summarizing techniques to create reports and insights from sales or customer data.
Progress0 / 4 steps