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 date-range for dataframe

Create a date range expression.

This command requires a plugin

The polars date-range 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 date-range {flags}

Flags

  • --start, -s {any}: Start of the date range expression. This supports a string, date, or datetime expression.
  • --end, -e {any}: End of the date range expression. This supports a string, date, or datetime expression.
  • --interval, -i {any}: Interval of the date range expression. This supports a string or duration expression.
  • --closed, -c {string}: Closed window of the date range expression. This supports 'left', 'right', 'both', or 'none'.
  • --eager: Eagerly collect the date range expression into a dataframe.

Input/output types:

inputoutput
anypolars_expression
anypolars_dataframe

Examples

Eagerly create a column of dates from a start, end, and interval

> polars date-range --start 2022-01-01 --end 2022-01-05 --interval 1d --eager
╭───┬─────────────╮
│ # │   literal   │
├───┼─────────────┤
│ 0 │ 4 years ago │
│ 1 │ 4 years ago │
│ 2 │ 4 years ago │
│ 3 │ 4 years ago │
│ 4 │ 4 years ago │
╰───┴─────────────╯

Create a date range per group from the min and max of a date column

> [[date key]; [2024-01-01 one] [2024-01-02 one] [2024-01-01 two] [2024-01-03 two]]
    | polars into-lazy
    | polars group-by key
    | polars agg (polars date-range --start (polars col date | polars min) --end (polars col date | polars max) --interval 1d | polars as date_range)
    | polars collect
    | polars sort-by key
╭───┬─────┬───────────────╮
│ # │ key │  date_range   │
├───┼─────┼───────────────┤
│ 0 │ one │ ╭───┬───────╮ │
│   │     │ │ 0 │ 19723 │ │
│   │     │ │ 1 │ 19724 │ │
│   │     │ ╰───┴───────╯ │
│ 1 │ two │ ╭───┬───────╮ │
│   │     │ │ 0 │ 19723 │ │
│   │     │ │ 1 │ 19724 │ │
│   │     │ │ 2 │ 19725 │ │
│   │     │ ╰───┴───────╯ │
╰───┴─────┴───────────────╯