Machines on a Repeating Maintenance Rotation
Problem
Two CSV files describe a maintenance system. `machines.csv` holds each machine (`machine_id`, `machine_name`, `plant`); `maintenance_logs.csv` records each task performed on a machine (`log_id`, `machine_id`, `task`, `done_on`, `crew_hours`). Ordering each machine's logs by date, a machine follows a 'repeating rotation' when its tasks cycle through at least three distinct task types in a fixed order that repeats for at least two full cycles (so at least six logged tasks), with no gap longer than two days between consecutive tasks. For each such machine return one cycle's length (number of tasks before the pattern repeats) as `cycle_length` and the total `crew_hours` across the chained tasks as `total_hours`. Sort by `cycle_length` descending, then by `total_hours` descending.
Input data
Example rows — the live problem includes the full dataset.
| machine_id | machine_name | plant |
|---|---|---|
| 1 | Lathe One | North |
| 2 | Press Two | North |
| 3 | Mill Three | South |
| 4 | Drill Four | South |
| 5 | Saw Five | East |
| log_id | machine_id | task | done_on | crew_hours |
|---|---|---|---|---|
| 1 | 1 | oil | 2024-05-01 | 2 |
| 2 | 1 | belt | 2024-05-02 | 3 |
| 3 | 1 | filter | 2024-05-03 | 2.5 |
| 4 | 1 | oil | 2024-05-05 | 2 |
| 5 | 1 | belt | 2024-05-06 | 3 |
Expected output
Your answer should return 2 rows with the columns machine_name, cycle_length, total_hours.
Starter code (Pandas (Python))
import pandas as pd
def find_repeating_rotations(machines, maintenance_logs) -> pd.DataFrame:
# Your code here
return machinesSolve 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