Closest Pair of Sensor Stations
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
| east | north |
|---|---|
| 2 | 3 |
| 5 | 7 |
| 2 | 4 |
| 8 | 1 |
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 sensorstationSolve 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