AnalystPath

Monthly Stream Activity Above the Royalty Floor

PandasEasyJunior level~10 min

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.

streamplays
play_idplayed_onlistener_idroyalty_cents
12022-03-0450145
22022-03-1950260
32022-04-0250330
42022-04-2250328
52022-05-0850112

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 streamplays

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