Using Programs with Data
| English | Chinese | Pinyin |
|---|---|---|
| processing | 处理 | chǔ lǐ |
| iteration | 迭代 | dié dài |
| element | 元素 | yuán sù |
| filter | 过滤器 | guò lǜ qì |
| subset | 子集 | zi jí |
| combine | 合并 | hé bìng |
| transform | 转换 | zhuǎn huàn |
| Cleaning | 清洗 | qīng xǐ |
Programs that answer questions
- The last step is to use a program to actually work with data.
- A program does this by processing 处理 — taking data in, doing steps, giving back new information.
- The input might be a list of records, like students and their test scores.
- The output might be a new fact the data never directly stated — like the class average.
A program that takes scores in and gives back the average is doing:
Input → processing → output produces a new fact, the average.
Iteration visits every element
- To look at a whole data set, a program uses iteration 迭代 — repeating the same steps for each item.
- A loop visits each element 元素 (each item) of the list, one after another.
- So the program examines every record without a separate line for each one.
Average of five scores. A loop runs through $70, 85, 90, 60, 95$, adding each to a running total. After the loop the total is $400$; dividing by 5 gives the average $400 \div 5 = 80$ — information the raw list never stated.
Trace a loop that sums scores
A loop iterates through the list, adding each score to a running total. After the last pass the total is 400; dividing by 5 gives the average, 80.
Repeating the same steps for each item of a list is called ______.
A loop visits each element in turn.
A loop sums 70, 85, 90, 60, 95 to 400. What is the average of the 5 scores?
400 ÷ 5 = 80.
Filtering to a subset
- Often we want only some records. A filter 过滤器 keeps records that meet a condition and drops the rest.
- A condition is a test that is true or false for each record, like "score is 80 or higher."
- The filter produces a smaller subset 子集 — only the records that pass.
- Worked idea. Filtering $70, 85, 90, 60, 95$ with "score $\geq 80$" keeps $85, 90, 95$ — 3 students.
From 70, 85, 90, 60, 95, how many scores pass the filter "score ≥ 80"?
85, 90, 95 pass — a subset of 3.
The smaller group of records that pass a filter's condition is a ______.
A filter produces a subset of the original records.
Why clean the data before calculating?
Dirty data gives a wrong answer, so clean first for reliable results.
Combine, transform, and clean
- A program can combine 合并 data from several sources — matching names to scores by a shared ID.
- Or transform 转换 it — converting Celsius to Fahrenheit, or raw scores to percentages.
- Cleaning 清洗 inside the program (remove duplicates, skip blanks) keeps results reliable.
- Dirty data misleads: a duplicate skews the average, and a blank could crash the calculation.
A program processes data: input records in, new information out. Iteration visits every element to compute totals and averages; a filter keeps a subset meeting a condition. Programs also combine sources, transform values, and clean the data first — because dirty data gives a wrong answer.