Ciaren

Change types

Change types — castDtypes

Convert column data types.

Use cases

  • Turn numbers read as text ("42") into real integers/floats for math.
  • Parse a date column into a real datetime so sorting and Extract date parts work.
  • Coerce a dirty column, sending unparseable values to null instead of failing.

What it does

Rewrites the column values to the target type. With errors: coerce, rows with unparseable values become null rather than crashing the run.

Before
order_idamountordered_at
1001120.52024-01-03
1002bad2024-01-04
100389.02024-01-05
3 rows · 3 cols
Change types (amount→float errors=coerce, ordered_at→datetime)
After
order_idamountordered_at
1001120.52024-01-03
1002null2024-01-04
1003892024-01-05
3 rows · 3 cols

Configuration

Config keyTypeRequiredDescription
castsobjectYes{ "col": "dtype" } — dtype is integer, float, boolean, string, or datetime
formatstringNodatetime parse format (e.g. %Y-%m-%d)
errorsstringNoraise (default) or coerce (invalid → null)

Generated Python code

df_2 = df_1.assign(amount=lambda _d: _d['amount'].astype('float64'), ordered_at=lambda _d: pd.to_datetime(_d['ordered_at']))

Tips & common mistakes

  • Use coerce for dirty data. With errors: raise (the default), a single unparseable value fails the whole run; coerce turns bad values into null.
  • Give datetimes a format when the layout is unambiguous (e.g. %m-%Y) — it's faster and avoids mis-parsing day/month order.
  • For text-to-date parsing across several columns at once, see Parse dates.

See also