Total Machine Run-Time in Days
Problem
You are given a DataFrame `machinelog` (CSV `machinelog.csv`) with columns machine_id, logged_at (a timestamp), and event (either `power_on` or `power_off`). For each machine the events alternate: a machine runs from a `power_on` until the very next event for that machine. Add up the running time across all machines and report it as whole days, rounded down, in a single column `run_days`.
Input data
Example rows — the live problem includes the full dataset.
machinelog
| machine_id | logged_at | event |
|---|---|---|
| 1 | 2024-03-01 08:00:00 | power_on |
| 1 | 2024-03-03 08:00:00 | power_off |
| 1 | 2024-03-04 06:00:00 | power_on |
| 1 | 2024-03-04 17:00:00 | power_off |
| 2 | 2024-03-02 12:00:00 | power_on |
Expected output
Your answer should return 1 row with the columns run_days.
Starter code (Pandas (Python))
import pandas as pd
def total_machine_run_time_in_days(machinelog) -> pd.DataFrame:
# Your code here
return machinelogSolve 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