Can you score 2.5 goals?
You cannot score 2.5 goals. You score 2 or 3. But you can run 2.5 kilometres. And your team colour is not a number at all.
All three are data, but they are three different kinds. The kind decides what you can do with the data. This lesson also turns words into data a computer can count.
Key words
| Word | What it means | Example |
|---|---|---|
| Discrete value | A counted number that jumps between whole values. | Goals: 0, 1, 2, 3 |
| Continuous value | A measured number that can be any value in a range. | Height: 1.723 metres |
| Categorical value | The name of a group. | Red, blue, green |
| Codify | To turn words into a fixed set of codes a computer can count. | "The coach was late" becomes "transport" |
| Single object | Data stored and read as one whole piece. | A photo or a comment |
| Structured data | Data in a fixed shape of rows and columns. | A table |
| Qualitative data | Data that describes in words, pictures or sound. | A comment |
| Quantitative data | Data that is a number. | 5 stars |
The cells students fill in are left blank in this preview.
Which kind of value?
Have a go
Loading…
Your answers are marked here and are not kept. A college account keeps every student’s marks.
Discrete: you count it
You count a discrete value. There is a gap between one value and the next.
Goals, students, cars, brothers and sisters. You can have 2 or 3. You cannot have 2.5.
Continuous: you measure it
You measure a continuous value. It can be any value, even between two others.
Height, weight, time, temperature. 1.7 metres, 1.72 metres, 1.723 metres. How exact it is depends on the tool you use.
Categorical: you group it
A categorical value is the name of a group. Colour, country, bus route, year group.
You can count how many are in each group. You cannot add "red" and "blue". Careful: a bus route such as 42 looks like a number, but it is only a name.
Quick check: which kind?
Have a go
Quick check: which kind?
4 questionsThree kinds of value
| Kind | Question | Example | Can use decimals? |
|---|---|---|---|
| Discrete | How many? | Goals scored: 3 | No |
| Continuous | How much? How long? | Journey time: 12.5 minutes | Yes |
| Categorical | Which group? | Bus route: 42 | No, it is a name |
The cells students fill in are left blank in this preview.
Words are stored as one piece
A comment such as "The coach was late" is qualitative data. A computer stores it as a single object: one whole piece. You get the whole comment or nothing.
You cannot ask "how many comments are about transport?" You must read each one first.
Codify: turn words into groups
To count words, give each comment a group. This is to codify it.
"The coach was late" becomes the code "transport". "Lunch was small" becomes "food". Now the data is structured: a category in a column. You can count it, sort it and chart it.
Try it: codify one comment
comment = "We waited a long time for the coach"
text = comment.lower()
if "coach" in text or "late" in text or "wait" in text:
category = "transport"
# elif means: if the line above was not true, try this one.
elif "lunch" in text or "food" in text:
category = "food"
else:
category = "other"
print("Comment:", comment)
print("Code:", category)
# Change the comment to "Lunch was too small" and run it again.
Make a free account to save your work and track your progress.
From a comment to a count
Your turn: codify the comments
A school trip survey has free text comments. Fill in two functions. The first turns one comment into one category: transport, food, activity or other. The second counts how many comments are in each category. Press Run Tests to check.
def codify(comment):
# Turn one comment into one category word. Ignore capital letters.
# If it has "coach", "late" or "wait" in it, give back "transport".
# Else if it has "lunch" or "food" in it, give back "food".
# Else if it has "museum", "castle" or "guide" in it, give back "activity".
# Otherwise give back "other".
return None
def count_categories(comments):
# Codify every comment. Give back a dictionary that counts each category,
# for example {"transport": 2, "food": 1}. Only list categories that appear.
return None
Make a free account to save your work, or press Start lab to work through the whole lesson.
Codifying loses something
Warning
Many people think a code keeps everything a comment says. It keeps only one idea. "The coach was late but the castle was great" has two ideas, so one code loses one of them. The detail and the feeling go too. So keep the original words as well, if you can.
Judge the choice
Have a go
Judge the choice
4 questionsKey words crossword
Have a go
Loading…
Your answers are marked here and are not kept. A college account keeps every student’s marks.
Watch: counted, measured, grouped and coding words
Press Play on the short film below. It starts with three values, then shows the three kinds, a comment and its code, then one myth.
Film: counted, measured, grouped and coding words
Counted, measured, grouped, and coding words
Every scene, as text
- The kind decides what you can do. 2 or 3 students, never 2.5 (discrete: you count it). Run 2.5 kilometres (continuous: you measure it). Your team colour (categorical: you group it).
- Three kinds of value. Discrete: how many? (you count it: no decimals). Continuous: how much? How long? (you measure it: decimals, like 12.5 minutes). Categorical: which group? (you group it: no decimals, it is a name).
- Categorical: you group it. Red, blue, green (categorical: the name of a group). Bus route: 42 (still a name: it only looks like a number). You can count how many are in each group.
- Words are stored as one piece. "The coach was late" (qualitative data: it describes in words; single object: one whole piece). You get the whole comment or nothing. How many comments are about transport? (to answer: read each one first).
- Codify: turn words into groups. A table of Comment and Code: The coach was late, transport; Lunch was small, food (codify: words into a fixed set of codes; structured: a category in a column).
- Myth (false): a code keeps everything a comment says. The coach was late but the castle was great (two ideas: the coach and the castle). That is not true: a code keeps only one idea. transport (code: keeps the coach, loses the castle). Keep the original words as well, if you can.
Final check
Have a go
Final check
5 questionsRemember
Tip
Discrete: counted. Continuous: measured. Categorical: grouped. Words are stored as one object. Codify them into groups to make them structured.