Top Reviewer and Best Episode
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_id | episode |
|---|---|
| 1 | Tidewater |
| 2 | Static Bloom |
| listener_id | handle |
|---|---|
| 1 | mara_k |
| 2 | devon |
| episode_id | listener_id | stars | posted_on |
|---|---|---|---|
| 1 | 1 | 5 | 2021-04-03 |
| 2 | 1 | 4 | 2021-04-10 |
| 1 | 2 | 5 | 2021-04-12 |
| 2 | 1 | 2 | 2021-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 reviewSolve 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