THINK FIRST·CODE LATER

← All labs

Find the weekly rhythm: weekday × hour

Problem

Input: a CSV trip_id,start_time. Derive the weekday (three-letter English name, e.g. Mon) and the hour. Print the weekday × hour count matrix (rows in calendar order Mon…Sun, only weekdays present; columns = hours present; missing cells 0), as printed by pandas to_string() of groupby([...]).size().unstack(fill_value=0) reindexed by weekday order.

Then print busiest cell: Mon 8:00 (on ties, the first in the order weekday name alphabetically, then hour), weekday peak hour: 8, weekend peak hour: 11 (the most frequent hour, smallest on ties; None if there are no trips in that group), and the time units of an Altair heat map with x = hours(start_time):O, y = day(start_time):O, colour = count():Q: x: hours | y: day | color: count.

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

v7-3-data-1.csv

trip_id,start_time
1,2026-03-02 08:05
2,2026-03-02 08:20
3,2026-03-02 08:40
4,2026-03-02 17:10
5,2026-03-03 08:15
6,2026-03-03 18:00
7,2026-03-03 17:30
8,2026-03-07 11:00
9,2026-03-07 11:45
10,2026-03-08 15:20
11,2026-03-08 11:10
What your program must print for v7-3-data-1.csv
hour     8   11  15  17  18
weekday                    
Mon       3   0   0   1   0
Tue       1   0   0   1   1
Sat       0   2   0   0   0
Sun       0   1   1   0   0
busiest cell: Mon 8:00
weekday peak hour: 8, weekend peak hour: 11
x: hours | y: day | color: count

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), in the folder that holds both files:

python my_lab.py < v7-3-data-1.csv

Windows PowerShell (the default terminal of VS Code on Windows) does not understand <:

Get-Content v7-3-data-1.csv | python my_lab.py

PyCharm: Run → Edit Configurations → tick Redirect input from and choose the file.

Jupyter: put this at the top of the cell that holds your program:

import sys
sys.stdin = open("v7-3-data-1.csv", encoding="utf-8")

Write it here, in Jupyter or in your IDE, then paste it. Run it on the sample input yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.