Each run starts with fresh data. Download any exported files before another run. Your written answers and code drafts are saved on this device; export your work to keep a backup.
M13C01 · Explore · predict · practice
Turn date text into dates
A date-looking string is still text until it is parsed. to_datetime() converts it to a date/time type. An explicit format removes ambiguity; impossible dates can be marked as NaT, pandas missing date value.
The first two dates are September 1 and September 3. February 30 remains invalid.
Compare your explanations
Read. Four-digit year, numeric month, and day of month.
Predict. It becomes NaT because it is not a valid calendar date.
Explain. It could mean January 2 or February 1, depending on the intended date convention.
One quick check
What is NaT?
What you should be able to explain. Parse known date formats explicitly.
M13C02 · Explore · predict · practice
Extract useful calendar parts
After parsing dates, the .dt accessor exposes calendar parts such as year, month, and weekday. These features are useful for grouping and checking patterns. Do not try to use .dt on unparsed strings.
Watch for this. A weekday pattern in twelve fictional records is a practice result, not evidence about real student behavior.
Your turn
Add Year and Day columns for the same join dates. Store only the first three rows in result, with columns Student_ID, Year, Month, and Day, then print result.
For the code check, keep these result variable names: result. Different valid approaches are welcome.
The years are 2026, the months are 9, and the day values are 1, 2, and 3.
Compare your explanations
Read. The column has been converted from text into a datetime type.
Predict. Yes, all join dates are in September, so every Month is 9.
Explain. September from different years would otherwise be grouped together.
One quick check
Which accessor provides calendar components?
What you should be able to explain. Create date features after parsing the date type.
M13C03 · Explore · predict · practice
Filter an explicit date interval
Date comparisons let you select a time interval. between() includes both boundaries by default; naming the inclusive rule makes your intent clearer. Here every date is a midnight date with no separate time-of-day information.
S003, S004, and S005 remain. The exclusive upper boundary removes S006.
Compare your explanations
Read. Yes; inclusive="both" includes both endpoints.
Predict. S003, S004, S005, and S006.
Explain. An included or excluded endpoint changes which records contribute to the analysis.
One quick check
Which operator excludes the upper boundary?
What you should be able to explain. State the start and end rules of every date filter.
M13C04 · Explore · predict · practice
Calculate elapsed time with a fixed reference
Subtracting dates produces timedeltas, which represent durations. .dt.days extracts whole days from those durations. A fixed reference date makes a classroom result reproducible when the file is opened later.
Read the example
df = students()
joined = pd.to_datetime(df["Join_Date"], format="%Y-%m-%d")
reference = pd.Timestamp("2026-10-01")
result = pd.DataFrame({"Student_ID": df["Student_ID"], "Days_enrolled": (reference - joined).dt.days})
print(result.head(4))