AnalystPath

Top Reviewer and Best Episode

PandasMediumMid level~10 min

Problem

You are given three DataFrames. `episode` has columns `episode_id` and `episode` (`episode_id` is unique). `listener` has columns `listener_id` and `handle` (`listener_id` is unique). `review` has columns `episode_id`, `listener_id`, `stars`, and `posted_on`; each row is one listener's star score for one episode on a date.

Return a single column named `result` containing exactly two rows, in this order:

1. The `handle` of the listener who posted the **most reviews** overall. Break ties by the handle that is alphabetically smallest.
2. The `episode` with the **highest average score** among reviews posted in **April 2021** (`2021-04-01` to `2021-04-30`). Break ties by the episode name that is alphabetically smallest.

**Example**

```text
If 'mara_k' posted the most reviews, and episode 'Tidewater' had the best
April average, the result is two rows: 'mara_k' then 'Tidewater'.
```

Input data

Example rows — the live problem includes the full dataset.

episode
episode_idepisode
1Tidewater
2Static Bloom
listener
listener_idhandle
1mara_k
2devon
review
episode_idlistener_idstarsposted_on
1152021-04-03
2142021-04-10
1252021-04-12
2122021-03-30

Expected output

Your answer should return 2 rows with the columns result.

Starter code (Pandas (Python))

import pandas as pd

def top_reviewer_and_best_episode(episode, listener, review) -> pd.DataFrame:
    # Your code here
    return review

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