Loyalty Tier of Each Subscriber
Problem
You are given three DataFrames. `subscribers` has columns `subscriber_id` and `handle` (`subscriber_id` is unique). `sessions` has columns `session_id` and `subscriber_id`; each row is one app session opened by a subscriber (`session_id` is unique). `orders` has columns `order_id` and `session_id`; each row is a purchase made during a session (`order_id` is unique).
For each subscriber, compute their conversion rate as `100 * (number of sessions that led to an order) / (number of sessions)` using integer division, then assign a tier: `Platinum` when the rate is at least `80`, `Silver` when it is in `[50, 80)`, `Bronze` when it is below `50`, and `Inactive` when the subscriber had no sessions at all. Return `subscriber_id`, `handle`, and the assigned `tier`, in any order.
Input data
Example rows — the live problem includes the full dataset.
| subscriber_id | handle |
|---|---|
| 1 | ava |
| 2 | ben |
| 3 | cy |
| 4 | dot |
| session_id | subscriber_id |
|---|---|
| 10 | 1 |
| 11 | 1 |
| 12 | 2 |
| 13 | 2 |
| 14 | 3 |
| order_id | session_id |
|---|---|
| 100 | 10 |
| 101 | 11 |
| 102 | 12 |
Expected output
Your answer should return 4 rows with the columns subscriber_id, handle, tier.
Starter code (Pandas (Python))
import pandas as pd
def loyalty_tier_of_each_subscriber(subscribers, sessions, orders) -> pd.DataFrame:
# Your code here
return subscribersSolve this Pandas question free
Write Pandas (Python) and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock