AnalystPath

Most-Voted Book of the Month

PandasMediumMid level~10 min

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
book_idtitle
1Tidewrack
2Glasswing
3Saltmarch
ballot
ballot_idbook_id
102
112
121
132

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 book

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