AnalystPath

Loyalty Tier of Each Subscriber

PandasMediumMid level~10 min

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.

subscribers
subscriber_idhandle
1ava
2ben
3cy
4dot
sessions
session_idsubscriber_id
101
111
122
132
143
orders
order_idsession_id
10010
10111
10212

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 subscribers

Solve 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

Related Pandas questions