Garages With No Free Spaces
Problem
You are given two DataFrames. `garages` has columns `garage_id`, `garage_name`, `district`, `zone_code`, `opened_year`, and `total_spaces` (how many cars the garage can hold). `parking_sessions` has columns `session_id`, `garage_id`, `plate`, `entry_time`, and `exit_time`; a car is currently parked when its `exit_time` is missing (NaN).
Find every garage that is completely full right now, meaning the number of currently parked cars equals `total_spaces`.
Return a DataFrame with columns `garage_id`, `garage_name`, `district`, `zone_code`, `opened_year`, and `parked_now`, ordered by `parked_now` descending, then `garage_name` ascending.
Input data
Example rows — the live problem includes the full dataset.
| garage_id | garage_name | district | zone_code | opened_year | total_spaces |
|---|---|---|---|---|---|
| 1 | Harbor Deck | Waterfront | WF | 2010 | 3 |
| 2 | Market Tower | Old Town | OT | 2005 | 3 |
| 3 | Station Lot | Midtown | MT | 2018 | 1 |
| 4 | Civic Plaza | Downtown | DT | 2001 | 2 |
| 5 | Riverside Ramp | Waterfront | WF | 2015 | 1 |
| session_id | garage_id | plate | entry_time | exit_time |
|---|---|---|---|---|
| 1 | 1 | AAA111 | 2024-01-15 | |
| 2 | 1 | BBB222 | 2024-01-20 | |
| 3 | 2 | CCC333 | 2024-01-10 | 2024-01-25 |
| 4 | 3 | DDD444 | 2024-02-01 | |
| 5 | 4 | EEE555 | 2024-01-05 |
Expected output
Your answer should return 2 rows with the columns garage_id, garage_name, district, zone_code, opened_year, parked_now.
Starter code (Pandas (Python))
import pandas as pd
def garages_with_no_free_spaces(garages, parking_sessions) -> pd.DataFrame:
# Your code here
return garagesSolve 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