Python
#36

Feature Normalization and Percentage of Group Total with transform()

MediumAmazon
Interview Question #36
Asked at Amazon

Given `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_namecategorysales
iPhonePhones8000
PixelPhones2000
MacBookLaptops15000
Expected Output Structure3 rows
product_namecategorysalescategory_sales_share
iPhonePhones80000.8
PixelPhones20000.2
MacBookLaptops150001
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.

Chat with us