Spec-Zone.ru › Nushell

polars replace-time-zone for dataframe

Replace the timezone information in a datetime column.

Signature

> polars replace-time-zone {flags} (time_zone)

Flags

  • --ambiguous, -a {oneof<string, nothing>}: Determine how to deal with ambiguous datetimes: raise (default): raise error earliest: use the earliest datetime latest: use the latest datetime null: set to null
  • --nonexistent, -n {oneof<string, nothing>}: Determine how to deal with non-existent datetimes: raise (default) or null.

Parameters

  • time_zone: Timezone for the Datetime Series. Pass null to unset time zone.

Input/output types:

input output
polars_expression polars_expression
polars_selector polars_expression

Examples

Apply timezone to a naive datetime

> ["2021-12-30 00:00:00" "2021-12-31 00:00:00"] | polars into-df
                    | polars as-datetime "%Y-%m-%d %H:%M:%S" --naive
                    | polars select (polars col datetime | polars replace-time-zone "America/New_York")
╭───┬─────────────╮
│ # │  datetime   │
├───┼─────────────┤
│ 0 │ 4 years ago │
│ 1 │ 4 years ago │
╰───┴─────────────╯

Apply timezone with ambiguous datetime

> ["2025-11-02 00:00:00", "2025-11-02 01:00:00", "2025-11-02 02:00:00", "2025-11-02 03:00:00"]
                    | polars into-df
                    | polars as-datetime "%Y-%m-%d %H:%M:%S" --naive
                    | polars select (polars col datetime | polars replace-time-zone "America/New_York" --ambiguous null)
╭───┬──────────────╮
│ # │   datetime   │
├───┼──────────────┤
│ 0 │ 6 months ago │
│ 1 │              │
│ 2 │ 6 months ago │
│ 3 │ 6 months ago │
╰───┴──────────────╯

Apply timezone with nonexistent datetime

> ["2025-03-09 01:00:00", "2025-03-09 02:00:00", "2025-03-09 03:00:00", "2025-03-09 04:00:00"]
                    | polars into-df
                    | polars as-datetime "%Y-%m-%d %H:%M:%S" --naive
                    | polars select (polars col datetime | polars replace-time-zone "America/New_York" --nonexistent null)
╭───┬────────────╮
│ # │  datetime  │
├───┼────────────┤
│ 0 │ a year ago │
│ 1 │            │
│ 2 │ a year ago │
│ 3 │ a year ago │
╰───┴────────────╯

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

Spec-Zone.ru

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