Nushell
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
GitHub
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
GitHub
  • Categories

    • Bits
    • Bytes
    • Chart
    • Conversions
    • Core
    • Database
    • Dataframe
    • Dataframe Or Lazyframe
    • Date
    • Debug
    • Default
    • Env
    • Experimental
    • Expression
    • Filesystem
    • Filters
    • Formats
    • Generators
    • Hash
    • History
    • Lazyframe
    • Math
    • Misc
    • Network
    • Path
    • Platform
    • Plugin
    • Prompt
    • Random
    • Removed
    • Shells
    • Strings
    • System
    • Viewers

polars replace-time-zone for dataframe

Replace the timezone information in a datetime column.

This command requires a plugin

The polars replace-time-zone 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 replace-time-zone {flags} (time_zone)

Flags

  • --ambiguous, -a {one_of(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 {one_of(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:

inputoutput
anyany

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 │ 3 years ago │
│ 1 │ 3 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 │ in 6 months │
│ 1 │             │
│ 2 │ in 6 months │
│ 3 │ in 6 months │
╰───┴─────────────╯

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 │ 2 months ago │
│ 1 │              │
│ 2 │ 2 months ago │
│ 3 │ 2 months ago │
╰───┴──────────────╯