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 unique for [dataframe or lazyframe](/commands/categories/dataframe or lazyframe.md)

Returns unique values from a dataframe.

This command requires a plugin

The polars unique 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 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:

inputoutput
dataframedataframe
expressionexpression

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 │
╰───┴───╯