Paul's Python CoursePPC

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.

About an hour and a half, in 19 steps.

Sign up free to open itLog in

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:

  1. tidy_text(register): name and parish with no spaces at either end, and in title case, like Church Street.
  2. read_dates(register): joined as real dates, read with parse_dates.
  3. make_numbers(register): age as a number, with blanks and unknown missing; launches as whole numbers, where none means 0.
  4. drop_impossible(register): any age over 100 made missing.
  5. 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.

What it prints
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

  1. A blank where a number should be
  2. Not a number
  3. Tidy every value at once
  4. One Peter Jago, or three?
  5. Three volunteers
  6. Text that should be numbers
  7. None, or nothing?
  8. Dates written three ways
  9. June or October?
  10. Changing some of the rows
  11. Four hundred and twelve
  12. Each row once
  13. Arthur Abbott, three times
  14. One step at a time
  15. No copy
  16. How Paul would do it
  17. Make the cleaning pipeline
  18. Ship it