AnalystPath

Most Recent Check-In per Locker

PandasEasyJunior level~10 min

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.

locker_use
session_idlocker_tagopened_atclosed_at
1LK-2042023-07-10 08:00:002023-07-10 09:15:00
2LK-1182023-07-10 07:30:002023-07-10 07:55:00
3LK-2042023-07-11 18:00:002023-07-11 19:40:00
4LK-1182023-07-12 06:00:002023-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_use

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