polars get-year for dataframe
Gets year from date.
This command requires a plugin
The polars get-year 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 get-year {flags}
Input/output types:
| input | output |
|---|---|
| polars_dataframe | polars_dataframe |
| polars_lazyframe | polars_lazyframe |
| polars_expression | polars_expression |
Examples
Returns year from a date
> let dt = ('2020-08-04T16:39:18+00:00' | into datetime --timezone 'UTC');
let df = ([$dt $dt] | polars into-df);
$df | polars get-year
╭───┬──────╮
│ # │ 0 │
├───┼──────┤
│ 0 │ 2020 │
│ 1 │ 2020 │
╰───┴──────╯Returns year from a date in an expression
> let dt = ('2020-08-04T16:39:18+00:00' | into datetime --timezone 'UTC');
let df = ([$dt $dt] | polars into-df);
$df | polars select (polars col 0 | polars get-year)
╭───┬──────╮
│ # │ 0 │
├───┼──────┤
│ 0 │ 2020 │
│ 1 │ 2020 │
╰───┴──────╯