polars datepart
for expression
Creates an expression for capturing the specified datepart in a column.
This command requires a plugin
The polars datepart
command resides in the polars
plugin. To use this command, you must install and register nu_plugin_polars
. See the Plugins chapter in the book for more information.
Signature
> polars datepart {flags} (Datepart name)
Parameters
Datepart name
: Part of the date to capture. Possible values are year, quarter, month, week, weekday, day, hour, minute, second, millisecond, microsecond, nanosecond
Input/output types:
input | output |
---|---|
any | any |
Examples
Creates an expression to capture the year date part
> [["2021-12-30T01:02:03.123456789"]] | polars into-df | polars as-datetime "%Y-%m-%dT%H:%M:%S.%9f" | polars with-column [(polars col datetime | polars datepart year | polars as datetime_year )]
╭───┬─────────────┬───────────────╮
│ # │ datetime │ datetime_year │
├───┼─────────────┼───────────────┤
│ 0 │ 2 years ago │ 2021 │
╰───┴─────────────┴───────────────╯
Creates an expression to capture multiple date parts
> [["2021-12-30T01:02:03.123456789"]] | polars into-df | polars as-datetime "%Y-%m-%dT%H:%M:%S.%9f" |
polars with-column [ (polars col datetime | polars datepart year | polars as datetime_year ),
(polars col datetime | polars datepart month | polars as datetime_month ),
(polars col datetime | polars datepart day | polars as datetime_day ),
(polars col datetime | polars datepart hour | polars as datetime_hour ),
(polars col datetime | polars datepart minute | polars as datetime_minute ),
(polars col datetime | polars datepart second | polars as datetime_second ),
(polars col datetime | polars datepart nanosecond | polars as datetime_ns ) ]
╭───┬─────────────┬───────────────┬────────────────┬──────────────┬───────────────┬─────────────────┬─────────────────┬─────────────╮
│ # │ datetime │ datetime_year │ datetime_month │ datetime_day │ datetime_hour │ datetime_minute │ datetime_second │ datetime_ns │
├───┼─────────────┼───────────────┼────────────────┼──────────────┼───────────────┼─────────────────┼─────────────────┼─────────────┤
│ 0 │ 2 years ago │ 2021 │ 12 │ 30 │ 1 │ 2 │ 3 │ 123456789 │
╰───┴─────────────┴───────────────┴────────────────┴──────────────┴───────────────┴─────────────────┴─────────────────┴─────────────╯