Python
All Top 50 Python & Pandas Interview Questions#32
Build Matrix Dashboards with pivot_table in Pandas
MediumFlipkartInterview Question #32
Asked at FlipkartGiven sales records with `region`, `category`, and `sales`, create a pivot table showing total sales across regions (rows) and categories (columns), including Grand Total margins.
Input Table: sales
3 rows preview| region | category | sales |
|---|---|---|
| North | Electronics | 1000 |
| North | Fashion | 500 |
| South | Electronics | 1200 |
Expected Output Structure3 rows
| region | Electronics | Fashion | All |
|---|---|---|---|
| North | 1000 | 500 | 1500 |
| South | 1200 | 0 | 1200 |
| All | 2200 | 500 | 2700 |
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
Click "Run & Test" to execute your Pandas code against the test assertions.