Python
#50

Multi-Condition Vectorization with np.select() in Pandas

MediumAmazon
Interview Question #50
Asked at Amazon

Given customer tenure in months and spend, categorize customers into: 'VIP' (spend > 100k), 'Loyal' (tenure > 24), 'New High Growth' (spend > 25k and tenure <= 6), and 'Standard' otherwise.

Input Table: customers
4 rows preview
namespendtenure
Aarav12000012
Bhavna1500036
Chirag300003
Divya1000010
Expected Output Structure4 rows
namesegment
AaravVIP
BhavnaLoyal
ChiragNew High Growth
DivyaStandard
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