Second-Priciest Listing per Neighborhood
Problem
A property portal gives you a DataFrame `listings` with an asking_price and the neighborhood each listing sits in. For each neighborhood, find the listings whose asking_price is the second-highest distinct price in that neighborhood. If several listings share that second-highest price, return all of them. Skip any neighborhood that has fewer than two distinct price levels. Return a DataFrame with columns listing_id and neighborhood, ordered by listing_id.
Input data
Example rows — the live problem includes the full dataset.
| listing_id | asking_price | neighborhood |
|---|---|---|
| 1 | 70000 | Harborview |
| 2 | 80000 | Harborview |
| 3 | 80000 | Harborview |
| 4 | 90000 | Harborview |
| 5 | 55000 | Old Mill |
Expected output
Your answer should return 4 rows with the columns listing_id, neighborhood.
Starter code (Pandas (Python))
import pandas as pd
def second_priciest_listing_per_neighborhood(listings) -> pd.DataFrame:
# Your code here
return listingsSolve 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