How do you standardize inconsistent units of measurement or number/currency formats to a canonical form?
Quick Overview
Asks how to clean a dataset whose measurements and prices arrive in mixed units, locale number formats and currencies. Tests parsing of messy strings, unit and currency conversion, precision for money, handling of ambiguous inputs, and auditability of the cleaned values.
How do you standardize inconsistent units of measurement or number/currency formats to a canonical form?
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: medium
Interview Round: Other
How do you standardize inconsistent units of measurement or number/currency formats to a canonical form?
For example, a product table might hold weights such as "2.5 lb", "1,134 g" and "40 oz", and prices such as "\$1,000.50" and "1.000,50 €".
```hint Parse before you convert
Think about what has to be pulled out of each raw string before any conversion factor applies, and what extra context that step needs.
```
```hint Strings that parse twice
Look for inputs that parse cleanly but mean different things depending on where they came from.
```
### What a Strong Answer Covers
- Choosing and documenting the canonical unit, numeric type and currency representation
- Parsing raw strings into a value and a unit or currency, including locale-dependent separators and ambiguous symbols
- Converting units and currencies correctly, including dated exchange rates and precision for money
- Handling inputs that cannot be resolved, and validating the converted values
- Keeping raw values and conversion details so the work can be audited
### Follow-up Questions
- How would you detect a column that mixes units with no label, such as heights in centimeters and inches?
- Which exchange rate would you use to convert historical transactions for a revenue report, and why?
- How would you store amounts for currencies with zero or three decimal places?
- How would you keep the cleaning step repeatable when next month's data brings new formats?
Overview: Asks how to clean a dataset whose measurements and prices arrive in mixed units, locale number formats and currencies. Tests parsing of messy strings, unit and currency conversion, precision for money, handling of ambiguous inputs, and auditability of the cleaned values.