Most Recent Check-In per Locker
Problem
You are given a DataFrame `locker_use` with columns `session_id`, `locker_tag`, `opened_at`, and `closed_at` (datetime strings). Each row is one rental session of a gym locker, with the moment it was opened and closed.
For every locker, find the latest moment it was closed. Output `locker_tag` and that latest close time (keep the column named `closed_at`), ordered by `closed_at` descending.
Input data
Example rows — the live problem includes the full dataset.
| session_id | locker_tag | opened_at | closed_at |
|---|---|---|---|
| 1 | LK-204 | 2023-07-10 08:00:00 | 2023-07-10 09:15:00 |
| 2 | LK-118 | 2023-07-10 07:30:00 | 2023-07-10 07:55:00 |
| 3 | LK-204 | 2023-07-11 18:00:00 | 2023-07-11 19:40:00 |
| 4 | LK-118 | 2023-07-12 06:00:00 | 2023-07-12 06:20:00 |
Expected output
Your answer should return 2 rows with the columns locker_tag, closed_at.
Starter code (Pandas (Python))
import pandas as pd
def most_recent_check_in_per_locker(locker_use) -> pd.DataFrame:
# Your code here
return locker_useSolve 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