Python
All Top 50 Python & Pandas 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: products
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
Click "Run & Test" to execute your Pandas code against the test assertions.