Python
All Top Python Interview Questions#36
Feature Normalization and Percentage of Group Total with transform()
MediumAmazonInterview Question #36
Asked at AmazonGiven `products` (product_name, category, sales), add a new column `category_sales_share` representing each product's sales divided by the total sales of its category.
Input Table: df
3 rows preview| product_name | category | sales |
|---|---|---|
| iPhone | Phones | 8000 |
| Pixel | Phones | 2000 |
| MacBook | Laptops | 15000 |
Expected Output Structure3 rows
| product_name | category | sales | category_sales_share |
|---|---|---|---|
| iPhone | Phones | 8000 | 0.8 |
| Pixel | Phones | 2000 | 0.2 |
| MacBook | Laptops | 15000 | 1 |
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)…