Concept demo by Alex Mercer. Fictional business, not client work. Fernhollow Supply Co. and every customer, phone number and email in the file are made up.Back to Alex Mercer's portfolio
Fernhollow Supply Co.Customer list cleanup

Data cleanup · CSV and Excel · Python

250 messy rows in. 211 clean customers out.

A made-up restaurant supply company in northern New England had a customer list pasted together from an old CRM export, a trade show sign-up sheet and a spreadsheet someone kept on the side. I wrote a script that fixes what can be fixed safely, merges the repeats, writes down every change, and hands back a short list of things a person should decide.

  1. 250rows in the file
  2. −5junk rows: blanks, a test entry, a header pasted twice
  3. −34repeats merged into the customer they belong to
  4. 211customers, one row each

1,187 cells fixed, every one logged with its before and after

15 questions left for a person, none of them guessed at

01 · Before and after

Some of the worst rows, as they came in

Flip between the original file and the cleaned rows. Changed cells are marked, and a cell with a dotted outline is one the script refused to guess at. Tap or hover a cell to see why. A · stands for a stray space.

Pick a marked cell to see what happened to it.

02 · What got fixed

Thirteen rules, each one boring on purpose

Every fix follows a written rule, and a rule only fires when the right answer is clear from the value itself or from the rest of the file. The numbers are cells changed in this file.

03 · Repeats

34 repeat rows, merged without losing anything

Two rows count as the same customer when they share an email or a phone number and the business names agree, or when the names match and the ZIP does too. The row with the most recent order is kept, its blanks are filled from the other row, and anything that disagrees goes into Notes instead of being thrown away.

Looked like repeats, kept apart on purpose

Merging two real customers is worse than leaving a repeat in, so these stayed separate.

    04 · Left for a person

    15 things I wouldn't guess at

    A phone number with a digit missing, an email without an @, two different places sharing one email address. Each one is left exactly as it was and listed with the reason, so someone who knows the customers can settle it in a few minutes. In the clean file these customers are marked Needs Review.

    The 5 rows that were dropped

      05 · The change log

      Every change, searchable

      Nothing changes silently. This is the same log that ships as changes.csv and as a tab in the workbook: row number, field, before, after and the rule.

      06 · What you get back

      The files, and how it runs

      The original file is never touched. Every run writes a fresh set of outputs, so the same script can clean next month's export too.

      Running it

      • Plain Python 3, standard library only. The Excel workbook needs openpyxl; without it you still get every CSV.
      • Columns are found by name, so a file with “Company” instead of “Business Name” still works.
      • The rules live in one file in plain lists: the account types, the state spellings, which states have one area code. Changing them for another business is a small edit.
      • 37 tests cover each rule, the repeat matching and a full run on the sample file.
      $ python3 clean.py customers.csv --out output/
      250 rows in, 5 junk rows dropped, 34 repeats merged
      into 34 customers, 211 customers out.
      1187 cells fixed across 245 rows; 15 things
      for a person to check.
        output/changes.csv
        output/duplicates.csv
        output/fernhollow-customers-CLEAN.csv
        output/fernhollow-customers-cleanup.xlsx
        output/needs-review.csv
        output/removed-rows.csv

      07 · For a real list

      How I'd handle yours

      1. Look at a sample first. Fifty rows or so is enough to see which problems the file really has and which columns matter.
      2. Agree on the rules. What counts as the same customer, which spellings map to what, what should never be changed. Written down before anything runs.
      3. Run it and send back the review list. You get the clean file, the change log and the short list of questions only you can answer.
      4. Fold in your answers and keep the script. The next export can go through the same rules.