polars datepart

For expression.

Creates an expression for capturing the specified datepart in a column.

warning 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.

Command Type

plugin

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
polars_expression polars_expression
polars_selector polars_expression

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" --naive | polars with-column [(polars col datetime | polars datepart year | polars as datetime_year )]
╭───┬─────────────┬───────────────╮
│ # │  datetime   │ datetime_year │
├───┼─────────────┼───────────────┤
│ 0 │ 4 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" --naive |
                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 │ da │ d │
│   │             │               │                │              │               │                 │ te │ a │
│   │             │               │                │              │               │                 │ ti │ t │
│   │             │               │                │              │               │                 │ me │ e │
│   │             │               │                │              │               │                 │ _s │ t │
│   │             │               │                │              │               │                 │ ec │ i │
│   │             │               │                │              │               │                 │ on │ m │
│   │             │               │                │              │               │                 │ d  │ e │
│   │             │               │                │              │               │                 │    │ _ │
│   │             │               │                │              │               │                 │    │ n │
│   │             │               │                │              │               │                 │    │ s │
├───┼─────────────┼───────────────┼────────────────┼──────────────┼───────────────┼─────────────────┼────┼───┤
│ 0 │ 4 years ago │          2021 │             12 │           30 │             1 │               2 │  3 │ 1 │
│   │             │               │                │              │               │                 │    │ 2 │
│   │             │               │                │              │               │                 │    │ 3 │
│   │             │               │                │              │               │                 │    │ 4 │
│   │             │               │                │              │               │                 │    │ 5 │
│   │             │               │                │              │               │                 │    │ 6 │
│   │             │               │                │              │               │                 │    │ 7 │
│   │             │               │                │              │               │                 │    │ 8 │
│   │             │               │                │              │               │                 │    │ 9 │
╰───┴─────────────┴───────────────┴────────────────┴──────────────┴───────────────┴─────────────────┴────┴───╯

Ported from nushell/nushell.github.io. Copyright (c) 2021 Nushell Project. MIT License.