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-ranges for dataframe

Create a column of date ranges.

This command requires a plugin

The polars date-ranges 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-ranges {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-ranges --start 2022-01-01 --end 2022-01-05 --interval 1d --eager
╭───┬───────────────╮
│ # │    literal    │
├───┼───────────────┤
│ 0 │ ╭───┬───────╮ │
│   │ │ 0 │ 18993 │ │
│   │ │ 1 │ 18994 │ │
│   │ │ 2 │ 18995 │ │
│   │ │ 3 │ 18996 │ │
│   │ │ 4 │ 18997 │ │
│   │ ╰───┴───────╯ │
╰───┴───────────────╯

Create a column of per-row date ranges from start and end date columns

> [[start end]; [2022-01-01 2022-01-03] [2022-01-02 2022-01-03]]
 | polars into-df
 | polars select (polars date-ranges --start (polars col start) --end (polars col end) --interval 1d | polars as date_range)
╭───┬───────────────╮
│ # │  date_range   │
├───┼───────────────┤
│ 0 │ ╭───┬───────╮ │
│   │ │ 0 │ 18993 │ │
│   │ │ 1 │ 18994 │ │
│   │ │ 2 │ 18995 │ │
│   │ ╰───┴───────╯ │
│ 1 │ ╭───┬───────╮ │
│   │ │ 0 │ 18994 │ │
│   │ │ 1 │ 18995 │ │
│   │ ╰───┴───────╯ │
╰───┴───────────────╯