Skip to learning content

DATA SCIENCE PYTHON PLAYGROUND

Data Foundations

← All challenges
IC07 · Measurements / activity · ~10–15 min

Compare two measurements

selection · missingness · summaries

Measurement profile

The question

Describe current-week activity in steps and minutes; do not mix in the previous week.

df Measurement profile

Your inputs

df

steps is a count; minutes is duration. Missing measurements are unknown, not zero.

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.
df · first 5 of 16 rows
record_idgroupdatestepsminutesweek
A001Morning2026-04-01250020Previous
A002Evening2026-04-09307027Current
A003Morning2026-04-10364034Current
A004Evening2026-04-04421041Previous
A005Morning2026-04-124780NoneCurrent
View all 16 rows
df · complete input
record_idgroupdatestepsminutesweek
A001Morning2026-04-01250020Previous
A002Evening2026-04-09307027Current
A003Morning2026-04-10364034Current
A004Evening2026-04-04421041Previous
A005Morning2026-04-124780NoneCurrent
A006Evening2026-04-13535055Current
A007Morning2026-04-07592021Previous
A008Evening2026-04-08264028Current
A009Morning2026-04-09321035Current
A010Evening2026-04-03378042Previous
A011Morning2026-04-11435049Current
A012Evening2026-04-12492056Current
A013Morning2026-04-06549022Previous
A014Evening2026-04-14606029Current
A015Morning2026-04-08278036Current
A016Evening2026-04-02335043Previous

The editable setup in Your Python creates these inputs when you run it.

Your task · Compare two measurements

Describe current-week activity in steps and minutes; do not mix in the previous week.

summaryDataFrameknownSeries

Deliverables

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.

Words in this task
missing
no value was supplied
  1. Current-week summaryOutputsummaryDataFrame
    1. Use the Current-week steps and minutes columns to create summary with their standard descriptive statistics (describe()).
    2. Each column should ignore its own missing values.
  2. Known measurementsOutputknownSeries
    1. Store the count of known values for steps and minutes in known.

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

A row may have one measurement without the other. How should that appear in a summary?

Hint 2 — Tools

describe(), count() and selection

Revisit: Describe numeric columns · Find missing values · Combine conditions · Answer one numerical question

Hint 3 — Approach

Select current-week measurements, summarise each numeric column and count the observations available for each.

Explained solution

Add these lines below # Your work in the editor. The supplied input setup is already there.

current = df.loc[df.week == 'Current', ['steps', 'minutes']]
summary = current.describe()
known = current.count()
summary
View supplied setup

This code is already at the top of the editor.

import pandas as pd

# Supplied input: df (16 rows)
df = pd.DataFrame(
    [
        ('A001', 'Morning', '2026-04-01', 2500, 20, 'Previous'),
        ('A002', 'Evening', '2026-04-09', 3070, 27, 'Current'),
        ('A003', 'Morning', '2026-04-10', 3640, 34, 'Current'),
        ('A004', 'Evening', '2026-04-04', 4210, 41, 'Previous'),
        ('A005', 'Morning', '2026-04-12', 4780, None, 'Current'),
        ('A006', 'Evening', '2026-04-13', 5350, 55, 'Current'),
        ('A007', 'Morning', '2026-04-07', 5920, 21, 'Previous'),
        ('A008', 'Evening', '2026-04-08', 2640, 28, 'Current'),
        ('A009', 'Morning', '2026-04-09', 3210, 35, 'Current'),
        ('A010', 'Evening', '2026-04-03', 3780, 42, 'Previous'),
        ('A011', 'Morning', '2026-04-11', 4350, 49, 'Current'),
        ('A012', 'Evening', '2026-04-12', 4920, 56, 'Current'),
        ('A013', 'Morning', '2026-04-06', 5490, 22, 'Previous'),
        ('A014', 'Evening', '2026-04-14', 6060, 29, 'Current'),
        ('A015', 'Morning', '2026-04-08', 2780, 36, 'Current'),
        ('A016', 'Evening', '2026-04-02', 3350, 43, 'Previous'),
    ],
    columns=['record_id', 'group', 'date', 'steps', 'minutes', 'week'],
)

Why these steps exist

  • Each column has its own observed count; an unknown duration does not invalidate a known step count.
  • The 50% row is the median. The standard deviation summarises variation in the observed sample.

Another valid approach

Selecting columns before or after the population filter is equivalent here. Keep the summary limited to the requested measures.

Tab: indent · Shift+Tab: outdent · Esc, then Tab: leave editor

Edit Python. Control or Command plus Enter runs it. Tab indents by four spaces. Shift plus Tab outdents. Press Escape, then Tab or Shift plus Tab to leave the editor.

Each run executes all editor code in a fresh Python session. Named outputs appear below when you run.

Python starts when you open a lesson.

Output

Run your code to see what Python returns.