daft.Expression.dt.truncate#
- Expression.dt.truncate(interval: str, relative_to: Optional[Expression] = None) Expression [source]#
Truncates the datetime column to the specified interval
Example
>>> import daft, datetime >>> df = daft.from_pydict({ ... "datetime": [ ... datetime.datetime(2021, 1, 1, 0, 1, 1), ... datetime.datetime(2021, 1, 1, 0, 1, 59), ... datetime.datetime(2021, 1, 1, 0, 2, 0), ... ], ... } ... ) >>> df.with_column("truncated", df["datetime"].dt.truncate("1 minute")).collect() ╭───────────────────────────────┬───────────────────────────────╮ │ datetime ┆ truncated │ │ --- ┆ --- │ │ Timestamp(Microseconds, None) ┆ Timestamp(Microseconds, None) │ ╞═══════════════════════════════╪═══════════════════════════════╡ │ 2021-01-01 00:01:01 ┆ 2021-01-01 00:01:00 │ ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤ │ 2021-01-01 00:01:59 ┆ 2021-01-01 00:01:00 │ ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤ │ 2021-01-01 00:02:00 ┆ 2021-01-01 00:02:00 │ ╰───────────────────────────────┴───────────────────────────────╯ (Showing first 3 of 3 rows)
- Parameters:
interval – The interval to truncate to. Must be a string representing a valid interval in “{integer} {unit}” format, e.g. “1 day”. Valid time units are: ‘microsecond’, ‘millisecond’, ‘second’, ‘minute’, ‘hour’, ‘day’, ‘week’.
relative_to – Optional timestamp to truncate relative to. If not provided, truncates to the start of the Unix epoch: 1970-01-01 00:00:00.
- Returns:
a DateTime expression truncated to the specified interval
- Return type:
Expression