DS What is Data
Data is a collection of recorded facts: numbers, words, dates, measurements, observations. On its own a single value such as 414 means little. Attached to a context — "414 bikes were rented on 1 April 2024 at 24.1 °C" — it becomes information you can reason about.
Structured and unstructured data
| Kind | Looks like | Examples |
|---|---|---|
| Structured | Rows and columns with a fixed meaning | Rental logs, sales tables, sensor readings |
| Semi-structured | Nested records with labels | JSON from an app, XML feeds |
| Unstructured | No predefined fields | Customer emails, photos, audio |
Most classic data science — and this course — works with structured data: a table where each row is one observation (one day, one customer, one trip) and each column is one variable (temperature, rides, weekday).
Riverside Bikes' app stores trips as semi-structured records. Turning them into a flat table is often the first job:
import json
raw = '''[
{"trip": 1, "station": "Old Bridge", "minutes": 14, "member": true},
{"trip": 2, "station": "Market Sq", "minutes": 32, "member": false},
{"trip": 3, "station": "Old Bridge", "minutes": 9, "member": true}
]'''
trips = json.loads(raw)
print("trip station minutes member")
for t in trips:
print(f"{t['trip']:>4} {t['station']:<11} {t['minutes']:>7} {t['member']}")trip station minutes member
1 Old Bridge 14 True
2 Market Sq 32 False
3 Old Bridge 9 True
Types of variables
Knowing a variable's type tells you which summaries and charts make sense.
| Type | Subtype | Example from Riverside Bikes | Sensible summary |
|---|---|---|---|
| Numerical (quantitative) | Continuous — any value in a range | temperature 24.1, trip length 13.5 min |
mean, standard deviation |
| Discrete — counts | rides per day 414 |
mean, median | |
| Categorical (qualitative) | Nominal — no order | station name, payment method | counts, mode |
| Ordinal — ordered | rider rating poor < ok < great | counts, median |
A number is not automatically numerical data: a station ID like 207 is a label, and averaging IDs is meaningless.
station_ids = [207, 113, 207, 350, 113, 207]
ratings = ["great", "ok", "great", "poor", "ok", "great"]
# Averaging labels gives a number with no meaning:
print("Mean station id:", sum(station_ids) / len(station_ids))
# Counting them is what makes sense:
from collections import Counter
print("Trips per station:", Counter(station_ids))
print("Most common rating:", Counter(ratings).most_common(1)[0][0])Mean station id: 199.5
Trips per station: Counter({207: 3, 113: 2, 350: 1})
Most common rating: great
Where data comes from
- Logs and transactions — every rental, payment or click is recorded automatically.
- Sensors — the weather station on the town hall roof.
- Surveys and forms — rider satisfaction ratings.
- Public and open data — official weather records, holiday calendars.
- Experiments — e.g. trying a discount on half of the stations.
How data was collected matters as much as the data itself: a survey answered only by happy riders tells you little about everyone else. We return to this in the Ethics & Bias lesson.
Data quality
Real data is rarely clean. Typical problems:
| Problem | Example |
|---|---|
| Missing values | The weather station was offline on 12 April |
| Wrong type | "25" stored as text instead of a number |
| Impossible values | Temperature -999 used as an "unknown" code |
| Duplicates | A day exported twice |
| Inconsistent labels | "Old Bridge", "old bridge", "Old Bridge " |
A quick sanity check catches many of them before they spoil an analysis:
temps = [24.1, 15.4, -999, 22.1, None, 29.4]
for i, t in enumerate(temps):
if t is None:
print(f"day {i}: missing")
elif not -30 <= t <= 45:
print(f"day {i}: impossible value {t}")
valid = [t for t in temps if t is not None and -30 <= t <= 45]
print("Valid readings:", valid)
print("Mean of valid readings:", round(sum(valid) / len(valid), 2))day 2: impossible value -999
day 4: missing
Valid readings: [24.1, 15.4, 22.1, 29.4]
Mean of valid readings: 22.75
Tip: Never "fix" data silently. Keep a note of every rule you apply (e.g. "dropped readings below −30 °C") so your results can be reproduced and questioned.
Test yourself
In a table of daily bike rentals, what does one row usually represent?
- One variable
- One observation (one day)
- One data type
- One chart
A station ID such as 207 is which kind of variable?
- Continuous numerical
- Discrete numerical
- Categorical (nominal)
- Ordinal
Rider ratings *poor < ok < great* are an example of…
- Nominal data
- Ordinal data
- Continuous data
- Unstructured data