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

Select columns whose names contain the given literal substring(s).

Signature

> polars selector contains {flags} ...rest

Parameters

  • ...rest: Literal substring(s) to search for in column names.

Input/output types:

inputoutput
anypolars_selector

Examples

Select columns whose names contain 'foo'

> {
    "foo_bar": [1.0, 2.0],
    "foo_baz": [3.0, 4.0],
    "qux": [5, 6],
} |
polars into-df --as-columns |
polars select (polars selector contains foo) |
polars sort-by foo_bar foo_baz |
polars collect
╭───┬─────────┬─────────╮
│ # │ foo_bar │ foo_baz │
├───┼─────────┼─────────┤
│ 0 │    1.00 │    3.00 │
│ 1 │    2.00 │    4.00 │
╰───┴─────────┴─────────╯

Select columns whose names contain 'foo' or 'bar'

> {
    "foo_x": [1, 2],
    "bar_x": [3, 4],
    "baz": [5, 6],
} |
polars into-df --as-columns |
polars select (polars selector contains foo bar) |
polars sort-by foo_x bar_x |
polars collect
╭───┬───────┬───────╮
│ # │ foo_x │ bar_x │
├───┼───────┼───────┤
│ 0 │     1 │     3 │
│ 1 │     2 │     4 │
╰───┴───────┴───────╯