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 selector by-index for expression

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

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:

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