0
0
Data Analysis Pythondata~30 mins

Aggregation-based features in Data Analysis Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Aggregation-based features
📖 Scenario: You work in a small online store. You have a list of orders with customer names and order amounts. You want to learn how to create new features by grouping data and calculating summary numbers like total spending per customer.
🎯 Goal: Build a small program that groups orders by customer and calculates the total amount each customer spent.
📋 What You'll Learn
Create a list of orders with customer names and amounts
Create a variable to hold the minimum amount to consider
Use a dictionary comprehension to sum amounts per customer only if the total is above the minimum
Print the resulting dictionary of customers and their total spending
💡 Why This Matters
🌍 Real World
Stores and businesses often need to summarize customer purchases to understand buying habits and target marketing.
💼 Career
Data analysts and data scientists frequently create aggregation features to prepare data for machine learning or reporting.
Progress0 / 4 steps
1
Create the orders list
Create a list called orders with these exact tuples: ("Alice", 50), ("Bob", 20), ("Alice", 30), ("Bob", 40), ("Charlie", 70).
Data Analysis Python
Hint

Use square brackets to create a list. Each order is a tuple with a name and an amount.

2
Set the minimum total amount
Create a variable called min_total and set it to 60.
Data Analysis Python
Hint

Just assign the number 60 to the variable min_total.

3
Calculate total spending per customer above minimum
Use a dictionary comprehension to create a dictionary called total_per_customer. It should sum all amounts per customer from orders and include only customers whose total is greater than or equal to min_total. Use customer and amount as variable names in your comprehension.
Data Analysis Python
Hint

First sum amounts per customer using a loop and a dictionary. Then use a dictionary comprehension to keep only those with total >= min_total.

4
Print the total spending per customer
Write a print statement to display the total_per_customer dictionary.
Data Analysis Python
Hint

Use print(total_per_customer) to show the result.