Average Workout Duration per Treadmill
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_id | session_id | phase | moment |
|---|---|---|---|
| 1 | 10 | start | 100.0 |
| 1 | 10 | finish | 130.0 |
| 1 | 11 | start | 200.0 |
| 1 | 11 | finish | 250.0 |
| 2 | 12 | start | 50.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_logSolve 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