THINK FIRST·CODE LATER

← All labs

Answer the task with numbers before drawing it

Problem

A chart must make the answer to a task visible. Compute the answers first, so you can check the chart. Standard input: a CSV with columns date,<item>,… (the second column labels items, e.g. district), a line ---, then tasks TARGET ATTRIBUTE [ATTRIBUTE]:

  • extremes a → extremes pm25: min 35 (Ouhai, 2026-03-01), max 95 (Ouhai, 2026-03-03) (first occurrence);
  • distribution a → distribution pm25: min 35, Q1 39.25, median 45, Q3 52, max 95 (pandas quantiles, :g);
  • outliers a → values outside [Q1 − 1.5·IQR, Q3 + 1.5·IQR]: outliers pm25 (outside [20.125, 71.125]): Ouhai 03-03 (95) (or none);
  • trends a → least-squares slope of the daily mean against day number: trends pm25: +5.75 per day (rising) over 4 days (rising if > 0.05, falling if < −0.05, else flat);
  • correlation a b → correlation temperature pm25: r = -0.53 (moderate negative) (strong if |r| ≥ 0.7, moderate if ≥ 0.4, else weak).

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.

v3-2-data-1.txt — first 14 lines of 15

date,district,pm25,temperature
2026-03-01,Lucheng,42,12
2026-03-01,Ouhai,35,13
2026-03-02,Lucheng,48,11
2026-03-02,Ouhai,37,12
2026-03-03,Lucheng,51,10
2026-03-03,Ouhai,95,10
2026-03-04,Lucheng,55,9
2026-03-04,Ouhai,40,10
---
extremes pm25
distribution pm25
outliers pm25
trends pm25
What your program must print for v3-2-data-1.txt
extremes pm25: min 35 (Ouhai, 2026-03-01), max 95 (Ouhai, 2026-03-03)
distribution pm25: min 35, Q1 39.25, median 45, Q3 52, max 95
outliers pm25 (outside [20.125, 71.125]): Ouhai 03-03 (95)
trends pm25: +5.75 per day (rising) over 4 days
correlation temperature pm25: r = -0.53 (moderate negative)

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

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

Get-Content v3-2-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("v3-2-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.