AnalystPath

Adjacent Open Parking Spots

PandasEasyJunior level~10 min

Problem

A `ParkingSpot` DataFrame lists numbered spots in a single row of a lot. Each spot has a number `spot_no` and a flag `is_open` (1 = open, 0 = taken).

Report every open spot that sits next to at least one other open spot — that is, an open spot whose immediate lower-numbered neighbour or immediate higher-numbered neighbour is also open. Return a single column `spot_no`, sorted ascending.

Input data

Example rows — the live problem includes the full dataset.

parkingspot
spot_nois_open
11
20
31
41
51

Expected output

Your answer should return 3 rows with the columns spot_no.

Starter code (Pandas (Python))

import pandas as pd

def adjacent_open_spots(parkingspot: pd.DataFrame) -> pd.DataFrame:
    # Your code here
    return parkingspot

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