AnalystPath

Listening Mix by Membership Tier

PandasMediumMid level~10 min

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.

plays
play_idmember_idmodeminutes
7274123video4.5
2425123audio3.5
1413456audio5.67
2536456video3.0
8564456audio8.24
members
member_idtier
123Gold
789Silver
456Bronze

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 plays

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