City with Most Amenities
Problem
**[Asked at Airbnb]**
Each listing has an `amenities` column with a comma-separated list of amenities.
Find the **city with the most total amenities** across all its listings.
Return `city` and `total_amenities`.
Input data
Example rows — the live problem includes the full dataset.
listings
| listing_id | city | amenities |
|---|---|---|
| 1 | New York | WiFi,Pool,Gym,Kitchen |
| 2 | New York | WiFi,Kitchen,Parking |
| 3 | Los Angeles | WiFi,Pool |
| 4 | Chicago | WiFi,Pool,Gym |
Expected output
Your answer should return 1 row with the columns city, total_amenities.
Starter code (Pandas (Python))
import pandas as pd
def city_with_most_amenities(listings: pd.DataFrame) -> 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