Spec-Zone.ru › Nushell

polars truncate for expression

Divide the date/datetime range into buckets.

Signature

> polars truncate {flags} (every)

Parameters

  • every: Period length for every interval (can be duration or str).

Input/output types:

input output
polars_expression polars_expression
polars_selector polars_expression

Examples

Truncate a series of dates by period length

> seq date -b 2025-01-01 --periods 4 --increment 6wk -o "%Y-%m-%d %H:%M:%S" | polars into-df | polars as-datetime "%F %H:%M:%S" --naive | polars select datetime (polars col datetime | polars truncate 5d37m | polars as truncated)
╭───┬────────────┬────────────╮
│ # │  datetime  │ truncated  │
├───┼────────────┼────────────┤
│ 0 │ a year ago │ a year ago │
│ 1 │ a year ago │ a year ago │
│ 2 │ a year ago │ a year ago │
│ 3 │ a year ago │ a year ago │
╰───┴────────────┴────────────╯

Notes

Each date/datetime is mapped to the start of its bucket using the corresponding local datetime. Note that weekly buckets start on Monday. Ambiguous results are localised using the DST offset of the original timestamp - for example, truncating '2022-11-06 01:30:00 CST' by '1h' results in '2022-11-06 01:00:00 CST', whereas truncating '2022-11-06 01:30:00 CDT' by '1h' results in '2022-11-06 01:00:00 CDT'.

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

Spec-Zone.ru

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