AnalystPath

Total Machine Run-Time in Days

PandasMediumMid level~10 min

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_idlogged_atevent
12024-03-01 08:00:00power_on
12024-03-03 08:00:00power_off
12024-03-04 06:00:00power_on
12024-03-04 17:00:00power_off
22024-03-02 12:00:00power_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 machinelog

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