Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Preview

DA 1.12: Changing and formatting data types

This is the first page of the lesson. Read it and have a go at the activities. The rest is in the full lesson.

55 minutes

Three spellings of one day

A bakery list holds the dates 02/03/2026, 2 March 2026 and 2026-03-02. They are one day, written three ways.

A computer sees three different pieces of text. Before any analysis, the dates must be changed into one type and one format.

Key words

WordWhat it meansExample
ConvertTo change data from one type to another.Text "12" to the number 12
FormatThe way a value is written down.Year, then month, then day
Type conversionChanging the kind of a value in code.int("12")
ParseTo read text and pull out its parts in a form a program can use.Split a date at each slash
CurrencyA money value, such as pounds and pence.£12.50
RequirementWhat the analysis must achieve.Total sales by day
ISO dateA date written year-month-day, which sorts correctly as text.2026-03-02

The cells students fill in are left blank in this preview.

By the end of this lesson

Note

I can change money, dates and yes or no values into one consistent type, and check the result.

Starter: what you already know

Have a go

Starter: what you already know

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Your answers are marked here and are not kept. A college account keeps every student’s marks.

Worked example: three messy values

Raw valueProblemFixed value
£12.50A pound sign makes it text1250 pence, a whole number
02/03/2026Day first, in text2026-03-02
YA letter, not true or falsetrue
Sam Extra spacesSam

The cells students fill in are left blank in this preview.

Try it: convert in DuckDB

Code: duckdb
select cast(price as decimal(8,2)) as price,
  strptime(day, '%d/%m/%Y')::date as day,
  paid = 'Y' as paid
from raw;

-- Try it: add price * 2 as double_price to the list.

Try it: convert in Python

Code: python
text = "£12.50"
clean = text.replace("£", "")
parts = clean.split(".")
pence = int(parts[0]) * 100 + int(parts[1])
print(pence, type(pence))

# Why whole pence? Whole numbers add up exactly. Decimals can drift.
# Try it: change the price to "£0.99" and press Run.

The lesson goes on

3 more parts of this lesson are in the full curriculum, with the tasks, the final check and the labs. A college account gives your students all of it.