Skip to content

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.

Introductory ~10 min7 steps

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

Read first

01

Text in disguise

Read

A 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.

Messy customer list
02

Read this date

Predict

Predict first

A date column contains 03/04/2024. Which day is it?

3 April4 MarchCan't tell
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.

03

Parse with explicit formats

In the app

Open 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.
04

Check what didn't parse

Explore

Parsing 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.

05

Units are part of the value

Read

A 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.

06

Check your understanding

Checkpoint

Check 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.

07

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.