Trial Users Who Became Buyers
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.
| user_ref | acted_at | action_id | action_type |
|---|---|---|---|
| 11 | 2024-01-01 09:00:00 | 1 | Trial |
| 11 | 2024-01-05 09:00:00 | 2 | Purchase |
| 11 | 2024-01-08 09:00:00 | 3 | Purchase |
| 12 | 2024-01-02 10:00:00 | 4 | Purchase |
| 12 | 2024-01-09 10:00:00 | 5 | Purchase |
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 activitySolve 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