Dates, units and column types
Turn text that looks like numbers, dates and flags into real types, without letting an ambiguous format choose for you.
You will be able to
- Recognize numbers, dates and true/false values stored as text
- Parse them in Prepare with explicit formats
- Record units so a column can't be misread later
Text in disguise
ReadA column's type decides what you can do with it. Text can't be averaged or sorted by time, so a number stored as text quietly drops out of your analysis.
The sample customer list stores income as 43613.50, $83,484.79 and 125,953 in one column. Dates arrive as 2023-02-02, 18.01.2024 and Dec 11, 2023. The is_active flag uses eight spellings: Y, Yes, yes, true, N, No, no and false.
Read this date
PredictPredict first
A date column contains 03/04/2024. Which day is it?
Reveal
The answer: Can't tell
You can't tell from one value. Month-first and day-first both fit. Look for a value that settles it, such as 25/04/2024, or ask who produced the file. A parser that guesses gets some rows wrong without any error.
Parse with explicit formats
In the appOpen Insights (⌘5) on the customer list. It reports text columns that hold dates or numbers, and each finding has Fix in Prepare.
In Prepare (⌘3), the steps are:
- Parse numbers handles currency signs and thousands separators.
- Parse dates tries the formats you list, in order. The first that fits wins, so put the unambiguous ones first.
- Parse true/false maps yes/no, Y/N and 1/0. Other text becomes missing.
Check what didn't parse
ExploreParsing can fail silently: a value that doesn't convert becomes missing. So compare the missing count before and after each parse.
Open the step's Changes view in your recipe. It lists row, column, before and after. A few new blanks may be real junk. Many new blanks mean a format you didn't list.
Units are part of the value
ReadA number without a unit is half a fact. Keep each column in one unit, say which one, and convert mixed units before you analyze. Heights in centimeters and inches averaged together produce a number that describes nobody.
The dataset's dictionary is the place to record units, and the Dataset card in Insights shares them with whoever reads your work.
Check your understanding
CheckpointCheck yourself
After you parse income as a number, the column has 40 more missing values than before. What should you do first?
Show the answer
Answer: b
New blanks are a message from the parser. Find out why they failed before you fill or drop anything; often the fix is one more format.
Check yourself
Which list of formats is the safer one for Parse dates, given that the first format that fits wins?
Show the answer
Answer: b
ISO dates can't be misread, so they are safe first. Use a slash format only after confirming day-first or month-first from values that settle it.
Recap
Recap- Numbers, dates and flags often arrive as text. Parse them on purpose.
- An ambiguous date needs evidence, not a guess.
- Compare missing counts before and after parsing, and record units in the dictionary.