Most-Voted Book of the Month
Problem
You are given two DataFrames.
`book`
```text
+---------+--------+
| Column | Type |
+---------+--------+
| book_id | int |
| title | object |
+---------+--------+
book_id is the unique key.
```
`ballot`
```text
+-----------+---------+
| Column | Type |
+-----------+---------+
| ballot_id | int |
| book_id | int |
+-----------+---------+
ballot_id is the unique key. Each row is one vote cast for the given book_id.
```
Find the `title` of the book that received the most votes (assume there is no tie). Return a DataFrame with a single column `title`.
Input data
Example rows — the live problem includes the full dataset.
| book_id | title |
|---|---|
| 1 | Tidewrack |
| 2 | Glasswing |
| 3 | Saltmarch |
| ballot_id | book_id |
|---|---|
| 10 | 2 |
| 11 | 2 |
| 12 | 1 |
| 13 | 2 |
Expected output
Your answer should return 1 row with the columns title.
Starter code (Pandas (Python))
import pandas as pd
def top_book(book: pd.DataFrame, ballot: pd.DataFrame) -> pd.DataFrame:
# Your code here
return bookSolve 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