Summarizing Sales Data with Named Aggregation
📖 Scenario: You work in a small store and have a list of sales records. Each record shows the product sold, the quantity sold, and the price per item. You want to find out the total quantity sold and the average price for each product.
🎯 Goal: Build a pandas DataFrame from the sales data, then use groupby with named aggregation to calculate the total quantity and average price per product.
📋 What You'll Learn
Create a pandas DataFrame called
sales with columns product, quantity, and price using the exact data provided.Create a variable called
agg_funcs that holds the named aggregation dictionary for total quantity and average price.Use
sales.groupby('product').agg(**agg_funcs) to group and aggregate the data.Print the resulting DataFrame.
💡 Why This Matters
🌍 Real World
Stores and businesses often need to summarize sales data to understand product performance and pricing trends.
💼 Career
Data analysts and data scientists use named aggregation in pandas to create clear, readable summaries of grouped data for reports and decision making.
Progress0 / 4 steps