Python
All Top Python Interview Questions#38
Flatten Nested List Columns with df.explode() in Pandas
EasyInterview Question #38
Given an order table where `product_ids` contains a list of items `[101, 102, 103]`, unnest the list so that each product appears on its own row with duplicate order details.
Input Table: df
2 rows preview| order_id | product_ids |
|---|---|
| 1 | 101,102 |
| 2 | 103 |
Expected Output Structure3 rows
| order_id | product_ids |
|---|---|
| 1 | 101 |
| 1 | 102 |
| 2 | 103 |
Interview Context
Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.
Python 3.10 (Pandas)
Environment Ready
Starting the real Python + pandas runtime (one-time download)…