AnalystPath

Second Most Expensive Book Price

PandasMediumMid level~10 min

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.

catalog_titles
title_idlist_price
140
272
355

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_titles

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