Machines With Quick Back-to-Back Runs
Problem
A DataFrame `runs` logs production runs on factory machines with columns `machine_id`, `run_start` and `run_end` (datetime strings), a unique `run_id`, and a `job_type` (such as `Mold` or `Cut`). A run is "quick back-to-back" when the same machine starts another run of the same `job_type` no more than 8 hours after the previous run of that same type ended.
Return a DataFrame with the distinct `machine_id` of every machine that has at least one quick back-to-back run, ordered ascending.
Input data
Example rows — the live problem includes the full dataset.
| machine_id | run_start | run_end | run_id | job_type |
|---|---|---|---|---|
| 101 | 2024-03-01 08:00:00 | 2024-03-01 09:00:00 | 1 | Mold |
| 101 | 2024-03-01 10:00:00 | 2024-03-01 11:00:00 | 2 | Cut |
| 102 | 2024-03-01 13:00:00 | 2024-03-01 14:00:00 | 3 | Mold |
| 102 | 2024-03-01 15:00:00 | 2024-03-01 16:00:00 | 4 | Mold |
| 101 | 2024-03-02 09:00:00 | 2024-03-02 10:00:00 | 5 | Mold |
Expected output
Your answer should return 1 row with the columns machine_id.
Starter code (Pandas (Python))
import pandas as pd
def quick_machines(runs) -> pd.DataFrame:
# Your code here
return runsSolve 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