Using agg() for Multiple Aggregations in Data Science
📖 Scenario: You work in a small grocery store. You have sales data for different fruits sold in the last week. You want to find out some useful information like the total quantity sold, the average price, and the highest price for each fruit.
🎯 Goal: Build a program that uses the agg() function to calculate multiple summary statistics (total quantity, average price, maximum price) for each fruit in the sales data.
📋 What You'll Learn
Create a pandas DataFrame with fruit sales data including columns: 'Fruit', 'Quantity', and 'Price'.
Create a variable to hold the aggregation functions using
agg().Use
groupby() on the 'Fruit' column and apply agg() to calculate total quantity, average price, and maximum price.Print the resulting aggregated DataFrame.
💡 Why This Matters
🌍 Real World
Stores and businesses often need to summarize sales or inventory data by categories to make decisions.
💼 Career
Data analysts and scientists use groupby and agg functions to quickly get insights from large datasets.
Progress0 / 4 steps