Listening Mix by Membership Tier
Problem
A media app logs how long each member spends in two modes. The `plays` DataFrame has one row per session: `play_id`, `member_id`, `mode` (either `audio` or `video`), and `minutes` spent (decimal). The `members` DataFrame maps each `member_id` to a membership `tier` (such as `Basic` or `Premium`).
For each membership tier, compute what percentage of the tier's total minutes was spent in `audio` mode and what percentage in `video` mode. Round both percentages to two decimal places.
Return `tier`, `audio_pct`, and `video_pct`. Order is not important.
Input data
Example rows — the live problem includes the full dataset.
| play_id | member_id | mode | minutes |
|---|---|---|---|
| 7274 | 123 | video | 4.5 |
| 2425 | 123 | audio | 3.5 |
| 1413 | 456 | audio | 5.67 |
| 2536 | 456 | video | 3.0 |
| 8564 | 456 | audio | 8.24 |
| member_id | tier |
|---|---|
| 123 | Gold |
| 789 | Silver |
| 456 | Bronze |
Expected output
Your answer should return 3 rows with the columns tier, audio_pct, video_pct.
Starter code (Pandas (Python))
import pandas as pd
def listening_mix(plays, members) -> pd.DataFrame:
# Your code here
return playsSolve 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