2.4 Using programs with dataFilter, transform, combine, visualize

Programs can be used to process data, which lets users discover information and create new knowledge. The course names a set of processes. Filtering keeps only the items that meet a condition. Transforming changes every element the same way, like doubling every value or converting units. Combining or comparing data produces a single result, like a total, an average or the maximum, or joins two data sets. Sorting puts data in order. Visualizing turns data into charts, graphs or maps. Clustering and classifying group or label similar items.
| Process | What it does | Example |
|---|---|---|
| Filter | Keep only the items that meet a condition | Only bike trips of 30 minutes or more |
| Transform | Change every item the same way | Convert every temperature to Fahrenheit |
| Combine or compare | Join data sets, or compute one value | Total minutes; the longest trip |
| Sort | Put the items in order | Trips from shortest to longest |
| Visualize | Show the data as a chart or map | A bar chart of trips per day |
| Cluster or classify | Group similar items, or label them | Commuter trips vs weekend rides |
?Wait, what does APPEND do?
Here's a filter, written in the exam's pseudocode. It goes through a list of bike-trip lengths in minutes and builds a new list that keeps only the trips of 30 minutes or more. FOR EACH visits every element in order, and the IF decides which ones to keep.
1trips ← [12, 45, 7, 30, 22, 61, 15]2longTrips ← []13FOR EACH m IN trips4{5 IF (m ≥ 30)26 {7 APPEND(longTrips, m)28 }9}10DISPLAY(longTrips)11DISPLAY(LENGTH(longTrips))
- line 2 An empty list to collect the results
- line 5-7 Filter: keep a trip only if it is 30 minutes or more
| m | m ≥ 30? | longTrips after |
|---|---|---|
| 12 | false | [] |
| 45 | true | [45] |
| 7 | false | [45] |
| 30 | true | [45, 30] |
| 22 | false | [45, 30] |
| 61 | true | [45, 30, 61] |
| 15 | false | [45, 30, 61] |
?Wait, what does LENGTH do?
A transform looks almost the same, but there's no IF: every element goes through the same formula and lands in the new list. Here every Celsius temperature becomes Fahrenheit. A chart of the result is a visualization, and patterns are often easier to spot in a picture than in a list of numbers.
1celsius ← [10, 25, 30, 0, -5]2fahrenheit ← []3FOR EACH c IN celsius4{5 APPEND(fahrenheit, c * 9 / 5 + 32)16}7DISPLAY(fahrenheit)
- line 5 Transform: the same formula applied to every item
Real data work is iterative and interactive. You filter, look at the result, notice something odd, clean it, filter differently, chart it, and ask a new question. Tools like spreadsheets help: they organize data in rows and columns and make sorting, filtering and charting quick. Search tools help you find specific information efficiently in large data sets. The course doesn't ask about any specific spreadsheet functions, only about what these processes do and what they can reveal.
I thought about it. Show me
1trips ← [12, 45, 7, 30, 22, 61, 15]2count ← 03total ← 04FOR EACH m IN trips5{6 IF (m ≥ 30)7 {8 count ← count + 19 total ← total + m10 }11}12DISPLAY(total / count)
- Set up a trace table with columns m, m ≥ 30?, count and total. Both start at 0.
- m = 12, false. m = 45, true: count 1, total 45. m = 7, false. m = 30, true: count 2, total 75.
Why?
30 ≥ 30 is true, so 30 counts. A > would have skipped it. - m = 22, false. m = 61, true: count 3, total 136. m = 15, false.
- After the loop, total / count = 136 / 3 = 45.33...
Why?
The program filters (≥ 30) and combines (a total and a count) to get the average length of a long trip.
Answer: It displays about 45.33: the average of the long trips 45, 30 and 61 (136 ÷ 3).
Stuck? Get a hint
- Only the trips that are at least 30 change count and total.
- Those trips are 45, 30 and 61.
- Add them, then divide by how many there are.
prices ← [4, 10, 7, 2]
result ← []
FOR EACH p IN prices
{
APPEND(result, p * 2)
}
DISPLAY(result)- A[8, 20, 14, 4]
- B[4, 10, 7, 2]
- C[8, 20, 14, 4, 4, 10, 7, 2]
- D46
Show the answer
A. This is a transform: each price is doubled and appended to result, in order. 46 would be the sum of the doubled prices, which this code never computes.
- ACompressing the trip data with lossy compression
- BCombining the trip data with daily weather data and visualizing trips per day by weather
- CDeleting all trips from rainy days
- DSorting the trips by bike ID
Show the answer
B. The question needs two sources, trips and weather, combined, and a chart makes the pattern visible. Deleting rainy days would remove exactly the data needed.

When a question shows a data program, trace it with a table, just like in Unit 3. Then name what it does in one word: filter (has an IF), transform (changes every item), or combine (produces one total, count or maximum).
- Programs process data to reveal information: filter, transform, combine or compare, sort, visualize, cluster and classify.
- Filter: FOR EACH with an IF that decides what to APPEND. Transform: APPEND a changed copy of every item.
- Combining data sources and visualizing data often reveal patterns that a single list hides.
- Data work is iterative: filter, look, clean, chart, and ask a better question.