28. How to Merge and Join Tables in pandas for Blinkit Data
28.1 Why Join Blinkit-Style Tables
Why. Orders know store_id. City manager name lives on the stores table. Rider phone lives on riders. One mega CSV every morning breaks when a store manager changes. Joins keep grain honest.
What.
- Fact-like table — orders (many rows, events).
- Dimension-like table — stores, riders, SKUs (one row per entity).
merge— bring columns from B onto A using keys (Excel XLOOKUP / Power BI relationship cousin — Chapter 8 map).
How.
Before you merge
- Name the grain of each table (“one row = one order”).
- Name the key (
store_id,rider_id). - Check uniqueness of the dimension key.
- Choose
how(usuallyleftfrom orders). - Compare
lenbefore and after.
Worked example A — Tables you will use.
| Table | Grain | Key |
|---|---|---|
| orders | one order | order_id (+ store_id, rider_id) |
| stores | one dark store | store_id |
| riders | one rider | rider_id |
Worked example B — Business question.
“Delivered GMV by store manager for Pune” needs orders ⨝ stores, then filter city, then groupby manager.
Worked example C — Chapter map.
Chapter 8 = first merge. Chapter 23 = explosion warning. This chapter = Blinkit ops patterns + validation.
Ravindra Bagale's Tip
Before you merge, write the grain of each table, for example “one row per order_id” for orders and “one row per store_id” for stores. Check that the key in the dimension table is clean and unique, and compare the row count before and after the merge. Only then run groupby for your GMV numbers.
Ravindra Bagale's Tip – मराठी
Merge करण्याआधी प्रत्येक table चा grain लिहा, उदाहरणार्थ orders साठी “one row per order_id” आणि stores साठी “one row per store_id”. Dimension table मधली key स्वच्छ आणि unique आहे ना ते तपासा, आणि merge आधी व नंतरचा row count तुलना करा. त्यानंतरच GMV च्या आकड्यांसाठी groupby चालवा.
Ravindra Bagale's Tip – हिंदी
Merge करने से पहले हर table का grain लिखो, जैसे orders के लिए “one row per order_id” और stores के लिए “one row per store_id”। जाँचो कि dimension table की key साफ़ और unique है, और merge से पहले व बाद का row count मिलाओ। उसके बाद ही GMV के numbers के लिए groupby चलाओ।