Monthly Stream Activity Above the Royalty Floor
Problem
You are given a DataFrame `streamplays` with columns `play_id`, `played_on` (a date string), `listener_id`, and `royalty_cents`.
Consider only plays that earned strictly more than 25 royalty cents. For each calendar month (the `YYYY-MM` prefix of `played_on`) that has at least one such play, report:
- `play_count`: how many qualifying plays happened that month
- `listener_count`: how many distinct listeners produced them
Return columns `play_month`, `play_count`, `listener_count`. Months with no qualifying plays are omitted.
Input data
Example rows — the live problem includes the full dataset.
| play_id | played_on | listener_id | royalty_cents |
|---|---|---|---|
| 1 | 2022-03-04 | 501 | 45 |
| 2 | 2022-03-19 | 502 | 60 |
| 3 | 2022-04-02 | 503 | 30 |
| 4 | 2022-04-22 | 503 | 28 |
| 5 | 2022-05-08 | 501 | 12 |
Expected output
Your answer should return 4 rows with the columns play_month, play_count, listener_count.
Starter code (Pandas (Python))
import pandas as pd
def monthly_stream_activity_above_the_royalty_floor(streamplays) -> pd.DataFrame:
# Your code here
return streamplaysSolve 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