Second Most Expensive Book Price
Problem
A bookshop keeps the listed price of every title in one DataFrame.
**DataFrame: `catalog_titles`**
| Column | Type |
|-------------|------|
| title_id | int |
| list_price | int |
Each row holds the listed price (in whole shekels) of one book; `title_id` is unique.
Return a DataFrame with a single column `runner_up_price` holding the **second highest distinct** `list_price`. If there is no second distinct price, the value must be `None`.
**Example** — with prices 40, 55 and 72, the second highest distinct price is 55.
Input data
Example rows — the live problem includes the full dataset.
| title_id | list_price |
|---|---|
| 1 | 40 |
| 2 | 72 |
| 3 | 55 |
Expected output
Your answer should return 1 row with the columns runner_up_price.
Starter code (Pandas (Python))
import pandas as pd
def second_dearest_title(catalog_titles) -> pd.DataFrame:
# Your code here
return catalog_titlesSolve 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