AnalystPath

Garages With No Free Spaces

PandasEasyJunior level~10 min

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.

garages
garage_idgarage_namedistrictzone_codeopened_yeartotal_spaces
1Harbor DeckWaterfrontWF20103
2Market TowerOld TownOT20053
3Station LotMidtownMT20181
4Civic PlazaDowntownDT20012
5Riverside RampWaterfrontWF20151
parking_sessions
session_idgarage_idplateentry_timeexit_time
11AAA1112024-01-15
21BBB2222024-01-20
32CCC3332024-01-102024-01-25
43DDD4442024-02-01
54EEE5552024-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 garages

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