Project 3 of 12, for Yahya
Data Cleaning Pipeline
Three volunteers typed up the river rescue crew register three different ways. A pandas pipeline cleans it once, in five written-down steps, so nobody has to again.
Act 5 needs a free account, so your work is saved as you go. Act 1 is open to everyone.
The brief
- YahyaThis is the river rescue crew register from the Archive, with everyone who's volunteered since 1925.
- YahyaThree volunteers typed it up, and each of them had their own ideas about dates.
- YahyaArthur Abbott's in it twice and apparently Samuel Vosper joined at 412. I've counted, and I'm upset.
- PaulClean it once, properly, and write down how you did it, then nobody has to do it again.
register.csv has the columns name, joined, age (on joining), parish and launches, all as the volunteers typed them.
Build a cleaning pipeline: five steps, each a function that takes a table and gives back a cleaner copy, run in order. PIPELINE lists them, and the report at the bottom, which prints what each step did and saves register_clean.csv, is written.
Write parse_dates(column), which reads a column of text dates written any of three ways (1960-01-09, 09/01/1960 or 9 Jan 1960) and leaves any it can't read missing. Then the steps:
tidy_text(register):nameandparishwith no spaces at either end, and in title case, likeChurch Street.read_dates(register):joinedas real dates, read withparse_dates.make_numbers(register):ageas a number, with blanks andunknownmissing;launchesas whole numbers, wherenonemeans 0.drop_impossible(register): any age over 100 made missing.drop_duplicates(register): rows that are the same appear once, labelled 0, 1, 2 and so on again.
Each step changes only its own columns. Then clean_register(raw) runs the register through every step in PIPELINE, in order, and gives back the result.
No step changes the table it's given. Yahya never writes on an original.
Read register.csv: 133 rows, 13 values missing tidy_text 133 rows, 13 values missing read_dates 133 rows, 13 values missing make_numbers 133 rows, 21 values missing drop_impossible 133 rows, 22 values missing drop_duplicates 128 rows, 21 values missing Saved register_clean.csv Crew on the register: 128 Joined from 1925 to 2023 Ages known for 108; average age on joining: 26.5 Most launches: Walter Kerrow, 251
What you learn
What's in it
- A blank where a number should be
- Not a number
- Tidy every value at once
- One Peter Jago, or three?
- Three volunteers
- Text that should be numbers
- None, or nothing?
- Dates written three ways
- June or October?
- Changing some of the rows
- Four hundred and twelve
- Each row once
- Arthur Abbott, three times
- One step at a time
- No copy
- How Paul would do it
- Make the cleaning pipeline
- Ship it