Aggregation with agg()
📖 Scenario: You work in a small store that sells fruits. You have a list of sales data with fruit names, quantities sold, and prices. You want to find out some summary information like total quantity sold and average price for each fruit.
🎯 Goal: Build a program that uses pandas to group the sales data by fruit and then uses agg() to calculate total quantity sold and average price for each fruit.
📋 What You'll Learn
Create a pandas DataFrame with the given sales data
Create a grouping variable for the fruit column
Use
agg() to calculate total quantity and average price per fruitPrint the resulting aggregated DataFrame
💡 Why This Matters
🌍 Real World
Stores and businesses often need to summarize sales data to understand which products sell the most and at what average price.
💼 Career
Data analysts and scientists use aggregation functions like <code>agg()</code> to quickly get insights from large datasets.
Progress0 / 4 steps