0
0
Data Analysis Pythondata~30 mins

Inner join in Data Analysis Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Inner Join with Python Dictionaries
📖 Scenario: You are working with two small datasets representing customers and their orders in a simple store system. You want to combine these datasets to see which customers placed which orders.
🎯 Goal: Build a Python script that performs an inner join on two dictionaries based on a common key, customer_id, to combine customer names with their order details.
📋 What You'll Learn
Create two dictionaries: customers and orders with exact entries
Create a list variable joined_data to store the inner join results
Use a for loop to iterate over orders and match customer_id with customers
Append tuples of (customer_name, order_id, product) to joined_data
💡 Why This Matters
🌍 Real World
Inner joins are used in databases and data analysis to combine related data from different tables based on common keys, like customer IDs.
💼 Career
Understanding inner joins is essential for data analysts, database administrators, and software developers working with relational data.
Progress0 / 4 steps
1
Create the customers dictionary
Create a dictionary called customers with these exact entries: 1: 'Alice', 2: 'Bob', 3: 'Charlie'.
Data Analysis Python
Hint

Use curly braces {} to create a dictionary with integer keys and string values.

2
Create the orders dictionary
Create a dictionary called orders with these exact entries: 101: {'customer_id': 1, 'product': 'Book'}, 102: {'customer_id': 2, 'product': 'Pen'}, 103: {'customer_id': 4, 'product': 'Notebook'}.
Data Analysis Python
Hint

Use nested dictionaries for each order with keys customer_id and product.

3
Create the joined_data list and loop to join
Create an empty list called joined_data. Use a for loop with variables order_id and order_info to iterate over orders.items(). Inside the loop, check if order_info['customer_id'] is in customers. If yes, append a tuple (customers[order_info['customer_id']], order_id, order_info['product']) to joined_data.
Data Analysis Python
Hint

Use orders.items() to get both order ID and info, then check if the customer ID exists in customers.

4
Complete the inner join by verifying joined_data
Add a final line that assigns result to joined_data to complete the inner join data structure.
Data Analysis Python
Hint

Simply assign the joined_data list to a new variable result to finalize.