The question
Prepare an activity extract that keeps each value connected to its measurement and unit.
df Long measurementsYour inputs
df
The measure label carries the unit: steps is a count, minutes is elapsed time. Never combine their numeric values into one total.
Field meanings and units
record_id- Activity-observation identifier.
group- Comparison group.
date- Calendar date supplied as YYYY-MM-DD text unless the task states it is invalid.
steps- Recorded step count, additive across observations.
minutes- Elapsed duration in minutes; unknown is not zero.
week- Current or Previous reporting week.
record_id | group | date | steps | minutes | week |
|---|---|---|---|---|---|
| A001 | Morning | 2026-04-01 | 2500 | 20 | Previous |
| A002 | Evening | 2026-04-01 | 3070 | 27 | Previous |
| A003 | Morning | 2026-04-02 | 3640 | 34 | Previous |
| A004 | Evening | 2026-04-02 | 4210 | 41 | Previous |
| A005 | Morning | 2026-04-03 | 4780 | 48 | Previous |
View all 12 rows
record_id | group | date | steps | minutes | week |
|---|---|---|---|---|---|
| A001 | Morning | 2026-04-01 | 2500 | 20 | Previous |
| A002 | Evening | 2026-04-01 | 3070 | 27 | Previous |
| A003 | Morning | 2026-04-02 | 3640 | 34 | Previous |
| A004 | Evening | 2026-04-02 | 4210 | 41 | Previous |
| A005 | Morning | 2026-04-03 | 4780 | 48 | Previous |
| A006 | Evening | 2026-04-03 | 5350 | 55 | Previous |
| A007 | Morning | 2026-04-04 | 5920 | 21 | Previous |
| A008 | Evening | 2026-04-04 | 2640 | 28 | Previous |
| A009 | Morning | 2026-04-05 | 3210 | 35 | Previous |
| A010 | Evening | 2026-04-05 | 3780 | 42 | Previous |
| A011 | Morning | 2026-04-06 | 4350 | 49 | Previous |
| A012 | Evening | 2026-04-06 | 4920 | 56 | Previous |
The editable setup in Your Python creates these inputs when you run it.
Prepare an activity extract that keeps each value connected to its measurement and unit.
longDataFrameduration_recordsDataFrameDeliverables
Make the outputs listed below. Use each name exactly as shown. Then choose Check answer.
Python name key
Teal outlines name table columns. Violet left rules name Python objects. Dotted rules mark syntax, functions and parameters. Use each name exactly as shown.
- One row per measurementOutput
longDataFrame- Create
longwithrecord_id,measureand value, usingstepsandminutesonly. - Include both measurements for every source record, including unknown values.
- Create
- Duration extractOutput
duration_recordsDataFrame- Create
duration_recordsfromlongformeasureminutesand value at least 35.
- Create
Data policy Keep all supplied source tables unchanged. Work on separate outputs.
Help Hints & explained solution
Choose the amount of help you need. Opening one hint does not reveal the others.
Hint 1 — Think
How will a reader know whether a value counts steps or measures minutes?
Hint 3 — Approach
Retain the record identifier while stacking the two measures, then select qualifying duration observations.
Explained solution
Add these lines below # Your work in the editor. The supplied input setup is already there.
long = df.melt(
id_vars=['record_id'],
value_vars=['steps', 'minutes'],
var_name='measure',
value_name='value',
)
duration_records = long[(long.measure == 'minutes') & (long.value >= 35)]
longView supplied setup
This code is already at the top of the editor.
import pandas as pd
# Supplied input: df (12 rows)
df = pd.DataFrame(
[
('A001', 'Morning', '2026-04-01', 2500, 20, 'Previous'),
('A002', 'Evening', '2026-04-01', 3070, 27, 'Previous'),
('A003', 'Morning', '2026-04-02', 3640, 34, 'Previous'),
('A004', 'Evening', '2026-04-02', 4210, 41, 'Previous'),
('A005', 'Morning', '2026-04-03', 4780, 48, 'Previous'),
('A006', 'Evening', '2026-04-03', 5350, 55, 'Previous'),
('A007', 'Morning', '2026-04-04', 5920, 21, 'Previous'),
('A008', 'Evening', '2026-04-04', 2640, 28, 'Previous'),
('A009', 'Morning', '2026-04-05', 3210, 35, 'Previous'),
('A010', 'Evening', '2026-04-05', 3780, 42, 'Previous'),
('A011', 'Morning', '2026-04-06', 4350, 49, 'Previous'),
('A012', 'Evening', '2026-04-06', 4920, 56, 'Previous'),
],
columns=['record_id', 'group', 'date', 'steps', 'minutes', 'week'],
)Why these steps exist
- The identifier is repeated beside each measurement so values retain their source record.
- Filtering on both measure and value prevents a large step count from being mistaken for a long duration.
Another valid approach
Equivalent reshaping is accepted if every requested record and measurement pair appears once with the correct value.