Spec-Zone.ru › Nushell

polars as-date for dataframe

Converts string to date.

Signature

> polars as-date {flags} (format)

Flags

  • --not-exact, -n: The format string may be contained in the date (e.g. foo-2021-01-01-bar could match 2021-01-01).

Parameters

  • format: Formatting date string.

Input/output types:

input output
polars_dataframe polars_dataframe
polars_lazyframe polars_lazyframe
polars_expression polars_expression

Examples

Converts string to date

> ["2021-12-30" "2021-12-31"] | polars into-df | polars as-date "%Y-%m-%d"
╭───┬─────────────╮
│ # │    date     │
├───┼─────────────┤
│ 0 │ 4 years ago │
│ 1 │ 4 years ago │
╰───┴─────────────╯

Converts string to date

> ["2021-12-30" "2021-12-31 21:00:00"] | polars into-df | polars as-date "%Y-%m-%d" --not-exact
╭───┬─────────────╮
│ # │    date     │
├───┼─────────────┤
│ 0 │ 4 years ago │
│ 1 │ 4 years ago │
╰───┴─────────────╯

Converts string to date in an expression

> ["2021-12-30" "2021-12-31 21:00:00"] | polars into-lazy | polars select (polars col 0 | polars as-date "%Y-%m-%d" --not-exact)
╭───┬─────────────╮
│ # │    date     │
├───┼─────────────┤
│ 0 │ 4 years ago │
│ 1 │ 4 years ago │
╰───┴─────────────╯

Output is of date type

> ["2021-12-30" "2021-12-31 21:00:00"] | polars into-df | polars as-date "%Y-%m-%d" --not-exact | polars schema
╭──────┬──────╮
│ date │ date │
╰──────┴──────╯

Notes

Format example: "%Y-%m-%d" => 2021-12-31 "%d-%m-%Y" => 31-12-2021 "%Y%m%d" => 2021319 (2021-03-19)

Copyright © 2019–2026 The Nushell Project DevelopersLicensed under the MIT License.
https://www.nushell.sh/commands/docs/polars_as-date.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API