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 col for expression

Creates a named column expression.

This command requires a plugin

The polars col 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 col {flags} (column name) ...rest

Flags

  • --type, -t: Treat column names as type names

Parameters

  • column name: Name of column to be used. '*' can be used for all columns. Accepts regular expression input; regular expressions should start with ^ and end with $.
  • ...rest: Additional columns to be used. Cannot be '*'

Input/output types:

inputoutput
anyexpression

Examples

Creates a named column expression and converts it to a nu object

> polars col a | polars into-nu
╭───────┬────────╮
│ expr  │ column │
│ value │ a      │
╰───────┴────────╯

Select all columns using the asterisk wildcard.

> [[a b]; [x 1] [y 2] [z 3]] | polars into-df | polars select (polars col '*') | polars collect
╭───┬───┬───╮
│ # │ a │ b │
├───┼───┼───┤
│ 0 │ x │ 1 │
│ 1 │ y │ 2 │
│ 2 │ z │ 3 │
╰───┴───┴───╯

Select multiple columns (cannot be used with asterisk wildcard)

> [[a b c]; [x 1 1.1] [y 2 2.2] [z 3 3.3]] | polars into-df | polars select (polars col b c | polars sum) | polars collect
╭───┬───┬──────╮
│ # │ b │  c   │
├───┼───┼──────┤
│ 0 │ 6 │ 6.60 │
╰───┴───┴──────╯

Select multiple columns by types (cannot be used with asterisk wildcard)

> [[a b c]; [x o 1.1] [y p 2.2] [z q 3.3]] | polars into-df | polars select (polars col str f64 --type | polars max) | polars collect
╭───┬───┬───┬──────╮
│ # │ a │ b │  c   │
├───┼───┼───┼──────┤
│ 0 │ z │ q │ 3.30 │
╰───┴───┴───┴──────╯

Select columns using a regular expression

> [[ham hamburger foo bar]; [1 11 2 a] [2 22 1 b]] | polars into-df | polars select (polars col '^ham.*$') | polars collect
╭───┬─────┬───────────╮
│ # │ ham │ hamburger │
├───┼─────┼───────────┤
│ 0 │   1 │        11 │
│ 1 │   2 │        22 │
╰───┴─────┴───────────╯