Spec-Zone.ru › Nushell

polars unique for [dataframe or lazyframe](/commands/categories/dataframe or lazyframe.md)

Returns unique values from a dataframe.

Signature

> polars unique {flags}

Flags

  • --subset, -s {any}: Subset of column(s) to use to maintain rows (lazy df).
  • --last, -l: Keeps last unique value. Default keeps first value (lazy df).
  • --maintain-order, -k: Keep the same order as the original DataFrame (lazy df).

Input/output types:

input output
polars_dataframe polars_dataframe
polars_lazyframe polars_lazyframe
polars_expression polars_expression

Examples

Returns unique values from a series

> [2 2 2 2 2] | polars into-df | polars unique
╭───┬───╮
│ # │ 0 │
├───┼───┤
│ 0 │ 2 │
╰───┴───╯

Returns unique values in a subset of lazyframe columns

> [[a b c]; [1 2 1] [2 2 2] [3 2 1]] | polars into-lazy | polars unique --subset [b c] | polars collect
╭───┬───┬───┬───╮
│ # │ a │ b │ c │
├───┼───┼───┼───┤
│ 0 │ 1 │ 2 │ 1 │
│ 1 │ 2 │ 2 │ 2 │
╰───┴───┴───┴───╯

Returns unique values in a subset of lazyframe columns

> [[a b c]; [1 2 1] [2 2 2] [3 2 1]]
    | polars into-lazy
    | polars unique --subset [b c] --last
    | polars collect
╭───┬───┬───┬───╮
│ # │ a │ b │ c │
├───┼───┼───┼───┤
│ 0 │ 2 │ 2 │ 2 │
│ 1 │ 3 │ 2 │ 1 │
╰───┴───┴───┴───╯

Returns unique values in a subset of lazyframe columns

> [[a]; [2] [1] [2]]
    | polars into-lazy
    | polars select (polars col a | polars unique)
    | polars collect
╭───┬───╮
│ # │ a │
├───┼───┤
│ 0 │ 1 │
│ 1 │ 2 │
╰───┴───╯

Returns unique values in a subset of lazyframe columns

> [[a]; [2] [1] [2]]
    | polars into-lazy
    | polars select (polars col a | polars unique --maintain-order)
    | polars collect
╭───┬───╮
│ # │ a │
├───┼───┤
│ 0 │ 2 │
│ 1 │ 1 │
╰───┴───╯

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

Spec-Zone.ru

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