AnalystPath

Closest Pair of Sensor Stations

PandasMediumMid level~10 min

Problem

A `SensorStation` DataFrame holds the grid coordinates of unique stations as `east` and `north`. Report the shortest straight-line (Euclidean) distance between any two distinct stations, rounded to 2 decimals, in a single column `nearest`.

Input data

Example rows — the live problem includes the full dataset.

sensorstation
eastnorth
23
57
24
81

Expected output

Your answer should return 1 row with the columns nearest.

Starter code (Pandas (Python))

import pandas as pd

def closest_stations(sensorstation: pd.DataFrame) -> pd.DataFrame:
    # Your code here
    return sensorstation

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