Skip to content

Coding categories cleanly

Merge spellings of the same level, keep levels that really differ apart, and handle rare levels with a stated rule.

Introductory ~9 min7 steps

What runs in CodeSplash

You will be able to

  • Clean case and whitespace so one level has one spelling
  • Merge near-duplicate spellings with Recode values and Find similar values
  • Decide when to group rare categories

Read first

01

One level, many spellings

Read

To a computer, New York, NEW YORK and New York␠␠ with trailing spaces are three different values. A bar chart gets three bars, and a test gets three groups.

The customer list has this problem in both city and plan.

Messy customer list
02

How many plans?

Predict

Predict first

The business sells three plans: basic, pro and enterprise. How many different non-empty spellings does the plan column contain?

Make your guess between 3 and 20 spellings, then reveal.

Reveal

Fifteen. Each plan appears in lower case, upper case and title case, and with leading or trailing spaces. Three levels look like fifteen.

03

Clean, then merge

In the app

In Prepare (⌘3), work from the mechanical to the judgment calls:

  1. Clean text trims whitespace and sets case. That settles most of plan.
  2. Recode values maps what remains with a lookup table. Its Find similar values button groups spellings such as newyork and new york; you choose the value to keep.
  3. Open Suggested fixes to see the same steps proposed from the profile.

Each step is a line in your recipe, so the merges are written down rather than lost in a spreadsheet.

04

Similar isn't the same

Read

A clustering tool proposes merges; you decide. Georgia the state and Georgia the country share a spelling and differ in meaning. Hospital A and Hospital B differ by one letter and are different places.

05

Rare levels

Explore

Group rare categories folds infrequent levels into one "Other" level. It helps when a model or a table would otherwise have dozens of tiny groups.

Try it on a copy of city, and look at what ends up inside "Other". Then ask whether anyone cares about one of those levels. A rare level can be the most important one: a rare complication is still the complication you came to study.

06

Check your understanding

Checkpoint

Check yourself

You compare satisfaction across plan before cleaning. What happens?

Show the answer

Answer: b

Nothing stops you. The test runs, on more groups than exist, with fewer people in each. That is why cleaning comes before testing.

Check yourself

Put these cleaning steps in a sensible order.

  1. 1Trim whitespace and set one case with Clean text
  2. 2Check the result with Frequencies
  3. 3Merge the remaining spellings with Recode values

Show the answer

The order:

  1. Trim whitespace and set one case with Clean text
  2. Merge the remaining spellings with Recode values
  3. Check the result with Frequencies

Mechanical cleaning first removes most of the variants, so the lookup table only has to handle what is left. Then verify.

07

Recap

Recap
  • Case and whitespace create phantom levels. Clean them first.
  • Recode what remains, and let Find similar values propose rather than decide.
  • Group rare levels only after checking that none of them is the point.