How do you standardize messy free-text or categorical fields with many spelling variants into a controlled vocabulary?
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: medium
Interview Round: Other
How do you clean and standardize messy free-text or categorical fields with many spelling variants into a controlled vocabulary?
For example, a `state` column holds values such as "NY", "N.Y.", " new york " and "New Yrok", all meant to be the same category.
```hint Cheap wins first
Before any fuzzy matching, ask how many of the variants differ only in case, spacing, accents or punctuation.
```
```hint Uncertain matches
Think about what should happen to a match the method is unsure about, and who makes the final call.
```
### Clarifying Questions to Ask
- Does an approved list of canonical values already exist, or does it have to be built from the data?
- How many rows and how many distinct raw values are there, and is this a one-off cleanup or a recurring feed?
- Which error costs more here: merging two distinct categories, or leaving a variant unmapped?
- Is there time and staff for human review, and who owns the vocabulary?
### What a Strong Answer Covers
- Normalization steps that collapse trivial variants, and the risk of normalizing too aggressively
- How the controlled vocabulary is defined and maintained
- A matching strategy that combines exact or alias lookup with fuzzy similarity and thresholds
- Human review of uncertain matches and a way to measure match quality
- How the mapping is stored, applied to new data, and enforced at entry
### Follow-up Questions
- How would you choose the auto-map threshold, and how would you know it is working?
- The field has 200,000 distinct raw values and 5,000 canonical values. How do you make matching fast enough?
- "Austria" and "Australia" score high on string similarity. How do you prevent merges like that?
- How do you handle a value that names two categories at once, such as "NY/NJ"?
Overview: Asks how to turn a messy text or categorical column full of spelling variants, abbreviations and typos into a fixed set of approved values. Tests normalization, alias tables, fuzzy matching with thresholds, human review and how to keep the mapping accurate as new data arrives.