The question
Compare mean activity duration between Morning and Evening groups using known durations only.
df Mean comparisonYour inputs
df
Each row is one Morning or Evening activity session. Duration text may be invalid; all other sessions remain eligible.
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 | bad | Previous |
View all 20 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 | bad | 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 |
The editable setup in Your Python creates these inputs when you run it.
Compare mean activity duration between Morning and Evening groups using known durations only.
meansSeriesfigFigureDeliverables
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.
- Group meansOutput
meansSeries- Store the mean parsed
minutesfor each group inmeans. - Omit invalid durations, not entire groups.
- Store the mean parsed
- FigureOutput
figFigure- Create
figcomparing the groupmeans. - Choose labelled bars or individual points; either orientation is valid.
- Bars must start at zero.
- Add a meaningful title and measure labels
- Display the figure.
Identify Group and Minutes on the appropriate axes; extra wording is welcome.
- 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
Does an unknown duration belong in the denominator of an observed mean?
Hint 2 — Tools
to_numeric(), groupby(), mean(), Axes.bar() or Axes.barh(), or Axes.scatter() for a labelled point comparison
Revisit: Convert numeric text · Summarise groups · Compare averages · Avoid misleading charts · Scatter plot
Hint 3 — Approach
Parse durations, calculate each group’s observed mean and compare the values on a fair zero-based axis.
Explained solution
Add these lines below # Your work in the editor. The supplied input setup is already there.
work = df.copy()
work['minutes'] = pd.to_numeric(work.minutes, errors='coerce')
means = work.groupby('group').minutes.mean()
fig, ax = plt.subplots()
ax.bar(means.index, means.values)
ax.set(title='Mean activity duration', xlabel='Group', ylabel='Minutes')
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, 'bad', '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 group mean uses only its known durations; zero-filled unknowns would pull it downward.
- A shared zero baseline makes the represented group means comparable without exaggerating their difference.
Another valid approach
Labelled individual points are also valid for comparing these summaries. Vertical and horizontal orientations are accepted; bars must use a zero baseline.