THINK FIRST·CODE LATER

← All labs

Layers, facets and concatenation

Problem

Input: a line guideline G, then a CSV date,district,pm25.

Build: line = line chart (x = date, y = pm25, colour = district); rule = a dashed horizontal rule at G; line + rule; line faceted by column="district:N"; and (line + rule) | bar chart of mean pm25 per district.

For each composite print its top-level structure from to_dict(): line: single with 1 part(s), line + rule: layer with 2 part(s), facet: facet with 1 part(s) -> {'column': 'district'}, line+rule | bars: hconcat with 2 part(s) (the first of layer, facet, hconcat, vconcat, concat, repeat present; number of parts = length of that list, 1 for facet/repeat/single). Finally print days over guideline: Lucheng 4 (count of rows with pm25 > G per district, alphabetical, or none).

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-4-data-1.txt

guideline 40
date,district,pm25
2026-03-01,Lucheng,42
2026-03-01,Ouhai,35
2026-03-01,Longwan,28
2026-03-02,Lucheng,55
2026-03-02,Ouhai,40
2026-03-02,Longwan,31
2026-03-03,Lucheng,61
2026-03-03,Ouhai,38
2026-03-03,Longwan,25
2026-03-04,Lucheng,48
2026-03-04,Ouhai,39
2026-03-04,Longwan,30
What your program must print for v7-4-data-1.txt
line: single with 1 part(s)
line + rule: layer with 2 part(s)
facet: facet with 1 part(s) -> {'column': 'district'}
line+rule | bars: hconcat with 2 part(s)
days over guideline: Lucheng 4

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-4-data-1.txt

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

Get-Content v7-4-data-1.txt | 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-4-data-1.txt", 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.