0
0
Data Analysis Pythondata~30 mins

Creating interaction features in Data Analysis Python - Try It Yourself

Choose your learning style9 modes available
Creating Interaction Features
📖 Scenario: You work as a data analyst for an online store. You have a small dataset with information about products: their price and quantity sold. You want to create a new feature that shows the total sales value for each product by multiplying price and quantity.
🎯 Goal: Build a small program that creates a dictionary with product prices and quantities, then creates a new dictionary with the total sales value for each product by multiplying price and quantity.
📋 What You'll Learn
Create a dictionary called prices with product names as keys and their prices as values.
Create a dictionary called quantities with product names as keys and quantities sold as values.
Create a new dictionary called total_sales where each product's value is the product of its price and quantity.
Print the total_sales dictionary.
💡 Why This Matters
🌍 Real World
Creating interaction features like total sales helps businesses understand product performance and make better decisions.
💼 Career
Data analysts and data scientists often create new features by combining existing data to improve models and insights.
Progress0 / 4 steps
1
Create the product price dictionary
Create a dictionary called prices with these exact entries: 'apple': 2, 'banana': 1, 'cherry': 3.
Data Analysis Python
Hint

Use curly braces {} to create a dictionary with keys and values separated by colons.

2
Create the product quantity dictionary
Create a dictionary called quantities with these exact entries: 'apple': 5, 'banana': 7, 'cherry': 3.
Data Analysis Python
Hint

Use the same dictionary syntax as before but with the quantities values.

3
Create the total sales dictionary using interaction features
Create a new dictionary called total_sales using a dictionary comprehension. For each product in prices, multiply its price by its quantity from quantities.
Data Analysis Python
Hint

Use a dictionary comprehension with {key: value for key in iterable} syntax.

4
Print the total sales dictionary
Print the total_sales dictionary to see the total sales value for each product.
Data Analysis Python
Hint

Use print(total_sales) to display the dictionary.