The question
Produce a chronological attendance table with identifiable learners and valid dates.
df Attendance handoffYour inputs
df
Only student and date are required. Preserve all columns and other values. An impossible date is not a valid attendance date.
Field meanings and units
submission_id- Attendance-submission identifier.
student- Learner label.
group- Comparison group.
hours- Study duration in hours.
score- Assessment score in points.
attended- Whether the learner attended.
date- Calendar date supplied as YYYY-MM-DD text unless the task states it is invalid.
submission_id | student | group | hours | score | attended | date |
|---|---|---|---|---|---|---|
| S007 | Learner 7 | A | 8 | 94 | true | 2026-04-04 |
| S001 | Learner 1 | A | 2 | 55 | false | 2026-04-01 |
| S004 | Learner 4 | B | 7 | 90 | true | 2026-04-02 |
| S002 | Learner 2 | B | 5 | 78 | true | 2026-04-01 |
| S003 | Learner 3 | A | 3 | 68 | true | 2026-02-30 |
View all 16 rows
submission_id | student | group | hours | score | attended | date |
|---|---|---|---|---|---|---|
| S007 | Learner 7 | A | 8 | 94 | true | 2026-04-04 |
| S001 | Learner 1 | A | 2 | 55 | false | 2026-04-01 |
| S004 | Learner 4 | B | 7 | 90 | true | 2026-04-02 |
| S002 | Learner 2 | B | 5 | 78 | true | 2026-04-01 |
| S003 | Learner 3 | A | 3 | 68 | true | 2026-02-30 |
| S005 | Learner 5 | A | 4 | None | false | 2026-04-03 |
| S006 | Learner 6 | B | 6 | 85 | true | 2026-04-03 |
| S008 | Learner 8 | B | 1 | 49 | true | None |
| S009 | Learner 9 | A | 2 | 56 | false | 2026-04-05 |
| S010 | None | B | 5 | 79 | true | 2026-04-05 |
| S011 | Learner 11 | A | 3 | 69 | true | 2026-04-06 |
| S012 | Learner 12 | B | 7 | 91 | true | 2026-04-06 |
| S013 | Learner 13 | A | 4 | 73 | false | 2026-04-07 |
| S014 | Learner 14 | B | 6 | 86 | true | 2026-04-07 |
| S015 | Learner 15 | A | 8 | 95 | true | 2026-04-08 |
| S016 | Learner 16 | B | 1 | 50 | true | 2026-04-08 |
The editable setup in Your Python creates these inputs when you run it.
Produce a chronological attendance table with identifiable learners and valid dates.
cleanDataFrameexcluded_countnumberDeliverables
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
- index
- the labels attached to rows or to Series values
- Attendance handoffOutput
cleanDataFrame- Create
cleanfrom a copy. - Parse date using YYYY-MM-DD, treating invalid dates as missing.
- Keep rows with known
studentand date. - Sort by date then
submission_idand reset to a consecutive index.
- Create
- Excluded recordsOutput
excluded_countnumber- Store the number excluded in
excluded_count.
- Store the number excluded in
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
Which fields make an attendance record identifiable and dated?
Hint 2 — Tools
to_datetime(), dropna(), sort_values() and reset_index()
Revisit: Parse dates · Drop missing rows · Sort and reset
Hint 3 — Approach
Parse dates before testing required fields, then order eligible records and report exclusions.
Explained solution
Add these lines below # Your work in the editor. The supplied input setup is already there.
clean = df.copy()
clean['date'] = pd.to_datetime(clean.date, format='%Y-%m-%d', errors='coerce')
clean = (
clean.dropna(subset=['student', 'date'])
.sort_values(['date', 'submission_id'])
.reset_index(drop=True)
)
excluded_count = len(df) - len(clean)
cleanView supplied setup
This code is already at the top of the editor.
import pandas as pd
# Supplied input: df (16 rows)
df = pd.DataFrame(
[
('S007', 'Learner 7', 'A', 8, 94, True, '2026-04-04'),
('S001', 'Learner 1', 'A', 2, 55, False, '2026-04-01'),
('S004', 'Learner 4', 'B', 7, 90, True, '2026-04-02'),
('S002', 'Learner 2', 'B', 5, 78, True, '2026-04-01'),
('S003', 'Learner 3', 'A', 3, 68, True, '2026-02-30'),
('S005', 'Learner 5', 'A', 4, None, False, '2026-04-03'),
('S006', 'Learner 6', 'B', 6, 85, True, '2026-04-03'),
('S008', 'Learner 8', 'B', 1, 49, True, None),
('S009', 'Learner 9', 'A', 2, 56, False, '2026-04-05'),
('S010', None, 'B', 5, 79, True, '2026-04-05'),
('S011', 'Learner 11', 'A', 3, 69, True, '2026-04-06'),
('S012', 'Learner 12', 'B', 7, 91, True, '2026-04-06'),
('S013', 'Learner 13', 'A', 4, 73, False, '2026-04-07'),
('S014', 'Learner 14', 'B', 6, 86, True, '2026-04-07'),
('S015', 'Learner 15', 'A', 8, 95, True, '2026-04-08'),
('S016', 'Learner 16', 'B', 1, 50, True, '2026-04-08'),
],
columns=['submission_id', 'student', 'group', 'hours', 'score', 'attended', 'date'],
)Why these steps exist
- Parsing first exposes impossible dates. Only student and date are required, so missing scores remain acceptable.
- Sorting makes the handoff chronological; resetting labels removes gaps left by excluded rows.
Another valid approach
Boolean eligibility masks are equivalent to removing rows missing the required fields after parsing.