AnalystPath

Average Workout Duration per Treadmill

PandasEasyJunior level~10 min

Problem

The `treadmill_log` DataFrame has columns `treadmill_id`, `session_id`, `phase`, and `moment`. Each treadmill records two rows per workout session: one with `phase = 'start'` and one with `phase = 'finish'`, where `moment` is the timestamp in seconds.\n\nFor every treadmill, compute the **average workout duration** across all of its sessions. A session's duration is its finish timestamp minus its start timestamp. Round to 3 decimal places, alias the result `avg_duration`, and return one row per treadmill.

Input data

Example rows — the live problem includes the full dataset.

treadmill_log
treadmill_idsession_idphasemoment
110start100.0
110finish130.0
111start200.0
111finish250.0
212start50.0

Expected output

Your answer should return 2 rows with the columns treadmill_id, avg_duration.

Starter code (Pandas (Python))

import pandas as pd

def avg_workout_duration(treadmill_log) -> pd.DataFrame:
    # Your code here
    return treadmill_log

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