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.16: Cleaning data to meet a need

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

60 minutes

Clean for what?

Two analysts get the same messy order table. One must report total sales. The other must email every customer.

They clean it differently. The first can ignore a missing phone number. The second cannot. Cleaning is never done for its own sake. It is done to meet a need.

Key words

WordWhat it meansExample
CleansingFixing or removing poor data so it can be used.Delete a repeat
ParameterA limit that shapes the task: what, when, how exact.Only March, sales only
AssessTo look at the data and list its faults.One repeat, one test row
RemoveTo take out rows that should not be there.The repeat
EditTo correct a value.Trim spaces, fix case
ParseTo read text and turn it into a form that is easy to use.£2.00 into 2.00
RequirementWhat the cleaned data must be able to do.Give total sales by item

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

By the end of this lesson

Note

I can clean a table for a stated need, using remove, edit and parse, 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: the order table

StepWhat we find or do
ParametersNeed: total sales by item, real orders only
AssessId 2 appears twice. Id 3 is a test. Names have spaces. Items have mixed case. Prices hold a pound sign
RemoveThe repeat of id 2 and the test row
EditTrim the name and make items small letters
ParseTurn the price text into a number
ReviewFour orders left. Totals now add up

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

Try it: clean in DuckDB

Code: duckdb
select distinct id, trim(customer) as customer, lower(item) as item, qty,
  cast(replace(price, '£', '') as decimal(8,2)) as price
from orders
where status <> 'test'
order by id;

-- Try it: remove the word distinct and see the repeat come back.

Try it: review the totals

Code: duckdb
select lower(item) as item,
  sum(qty * cast(replace(price, '£', '') as decimal(8,2))) as sales
from (select distinct * from orders where status <> 'test')
group by lower(item)
order by item;

-- Review: do the totals make sense for the need?

A common mistake

Warning

Many people clean everything they can see and never check the result against the need. Cleaning too much can throw away good rows. Always compare the cleaned data with the requirement, and keep the original.

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.