Merging on multiple keys
📖 Scenario: You work in a store's data team. You have two tables: one with sales data and another with product details. Both tables share two columns: store_id and product_id. You want to combine these tables to see sales along with product info.
🎯 Goal: Build a Python program that merges two data tables on the two keys store_id and product_id using pandas. The final output should show sales data with product names and categories.
📋 What You'll Learn
Create two pandas DataFrames named
sales and products with exact data given.Create a list variable named
keys containing the two keys 'store_id' and 'product_id'.Use pandas
merge function with on=keys to join sales and products.Print the merged DataFrame.
💡 Why This Matters
🌍 Real World
Merging data on multiple keys is common in business when combining sales, inventory, or customer data from different sources.
💼 Career
Data analysts and data scientists often merge datasets on multiple columns to prepare data for analysis or reporting.
Progress0 / 4 steps