polars selector by-index

For expression.

Select columns by their index position. Supports negative indices (e.g., -1 for the last column).

warning This command requires a plugin The polars selector by-index 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 selector by-index {flags} ...rest

Flags

  • --not-strict: Allow out-of-range indices without error.

Parameters

  • ...rest: Column index positions to select (negative indices count from the end).

Input/output types:

input output
any polars_selector

Examples

Select first and third columns by index

> [[a b c]; [1 2 3] [4 5 6]]
    | polars into-df
    | polars select (polars selector by-index 0 2)
    | polars collect
╭───┬───┬───╮
│ # │ a │ c │
├───┼───┼───┤
│ 0 │ 1 │ 3 │
│ 1 │ 4 │ 6 │
╰───┴───┴───╯

Select the last column using a negative index

> [[a b c]; [1 2 3] [4 5 6]]
    | polars into-df
    | polars select (polars selector by-index -1)
    | polars collect
╭───┬───╮
│ # │ c │
├───┼───┤
│ 0 │ 3 │
│ 1 │ 6 │
╰───┴───╯

Ported from nushell/nushell.github.io. Copyright (c) 2021 Nushell Project. MIT License.