Skip to learning content

DATA SCIENCE PYTHON PLAYGROUND

Data Foundations

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

What changed over time?

dates · aggregation · change over time

Daily activity

The question

Communicate the total recorded steps each day, combining all observations on that date.

df Daily activity

Your inputs

df

Each row is a separate activity session. Multiple sessions on a date contribute to that day’s total; include both groups and reporting weeks.

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 20 rows
record_idgroupdatestepsminutesweek
A001Morning2026-04-01250020Previous
A002Evening2026-04-01307027Previous
A003Morning2026-04-02364034Previous
A004Evening2026-04-02421041Previous
A005Morning2026-04-03478048Previous
View all 20 rows
df · complete input
record_idgroupdatestepsminutesweek
A001Morning2026-04-01250020Previous
A002Evening2026-04-01307027Previous
A003Morning2026-04-02364034Previous
A004Evening2026-04-02421041Previous
A005Morning2026-04-03478048Previous
A006Evening2026-04-03535055Previous
A007Morning2026-04-04592021Previous
A008Evening2026-04-04264028Previous
A009Morning2026-04-05321035Previous
A010Evening2026-04-05378042Previous
A011Morning2026-04-06435049Previous
A012Evening2026-04-06492056Previous
A013Morning2026-04-07549022Previous
A014Evening2026-04-07606029Previous
A015Morning2026-04-08278036Current
A016Evening2026-04-08335043Current
A017Morning2026-04-09392050Current
A018Evening2026-04-09449057Current
A019Morning2026-04-10506023Current
A020Evening2026-04-10563030Current

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

Your task · What changed over time?

Communicate the total recorded steps each day, combining all observations on that date.

dailySeriesfigFigure

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.

  1. Daily totalsOutputdailySeries
    1. Create daily as the sum of steps by parsed date, ordered chronologically.
    2. Do not average steps.
  2. FigureOutputfigFigure
    1. Create fig connecting the daily totals in time order, earliest first.
    2. Add a meaningful title and measure labels
    3. Display the figure.

    Identify Date and Steps on the appropriate axes; extra wording is welcome.

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

Do repeated dates represent separate days or contributions to the same day?

Hint 2 — Tools

to_datetime(), groupby(), sum() and Axes.plot()

Revisit: Parse dates · Summarise groups · Line plot · Finish a chart properly

Hint 3 — Approach

Parse dates, total observations within each date and show the daily values in time order.

Explained solution

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

work = df.copy()
work['date'] = pd.to_datetime(work.date, format='%Y-%m-%d')
daily = work.groupby('date').steps.sum().sort_index()
fig, ax = plt.subplots()
ax.plot(daily.index, daily.values, marker='o')
ax.set(title='Daily recorded steps', xlabel='Date', ylabel='Steps')
fig.tight_layout()
plt.show()
View supplied setup

This code is already at the top of the editor.

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

# Supplied input: df (20 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'),
        ('A013', 'Morning', '2026-04-07', 5490, 22, 'Previous'),
        ('A014', 'Evening', '2026-04-07', 6060, 29, 'Previous'),
        ('A015', 'Morning', '2026-04-08', 2780, 36, 'Current'),
        ('A016', 'Evening', '2026-04-08', 3350, 43, 'Current'),
        ('A017', 'Morning', '2026-04-09', 3920, 50, 'Current'),
        ('A018', 'Evening', '2026-04-09', 4490, 57, 'Current'),
        ('A019', 'Morning', '2026-04-10', 5060, 23, 'Current'),
        ('A020', 'Evening', '2026-04-10', 5630, 30, 'Current'),
    ],
    columns=['record_id', 'group', 'date', 'steps', 'minutes', 'week'],
)

Why these steps exist

  • Each date can contain several sessions, so daily steps add their contributions.
  • Chronological connections show change over time; connecting file order could suggest changes that never occurred.

Another valid approach

You can aggregate dates before or after explicitly sorting the summary; the plotted series must be chronological.

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. Display charts with plt.show().

Python starts when you open a lesson.

Output

Run your code to see what Python returns.