Ciaren

Parse dates

Parse dates — parseDates

Parse text columns into real datetimes so date operations (sorting, Extract date parts) work. Complements Extract date parts (which goes the other way: datetime → parts).

Use cases

  • Convert "2021-01-02" strings into datetimes before sorting or grouping by month.
  • Clean a messy date column, sending unparseable values to null.

What it does

Converts each matching text value to a datetime. Unparseable strings become null when errors=coerce (the default).

Before
idordered_at
12024-01-15
22024-02-20
3bad date
3 rows · 2 cols
Parse dates (columns=[ordered_at], errors=coerce)
After
idordered_atnew
12024-01-15 00:00:00
22024-02-20 00:00:00
3null
3 rows · 2 cols

Configuration

Config keyTypeRequiredDescription
columnsstring[]YesText columns to parse
formatstringNostrptime format (e.g. %d-%m-%Y); empty = auto-detect
errorsstringNocoerce (default, bad values → null) or raise

Generated Python code

df_2 = df_1.assign(ordered_at=lambda _d: pd.to_datetime(_d['ordered_at'], errors='coerce'))

Tips & common mistakes

  • Give a format for ambiguous dates (e.g. %d-%m-%Y vs %m-%d-%Y) so day and month aren't swapped.
  • coerce is the safe default — it won't fail a run on one bad value. Use raise when you want to catch unexpected formats early.

See also