AnalystPath

Trial Users Who Became Buyers

PandasHardSenior level~10 min

Problem

You are given a DataFrame `activity` with columns `user_ref`, `acted_at`, `action_id`, and `action_type`, where `action_type` is either `Trial` or `Purchase`.

For users whose **very first action** (earliest `acted_at`) was a `Trial`, count how many `Purchase` actions they later performed. Output `user_ref` and `purchase_count`, ordered by `purchase_count` descending and then `user_ref` descending.

Input data

Example rows — the live problem includes the full dataset.

activity
user_refacted_ataction_idaction_type
112024-01-01 09:00:001Trial
112024-01-05 09:00:002Purchase
112024-01-08 09:00:003Purchase
122024-01-02 10:00:004Purchase
122024-01-09 10:00:005Purchase

Expected output

Your answer should return 2 rows with the columns user_ref, purchase_count.

Starter code (Pandas (Python))

import pandas as pd

def trial_users_who_became_buyers(activity) -> pd.DataFrame:
    # Your code here
    return activity

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