polars selector contains

For expression.

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

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

Parameters

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

Input/output types:

input output
any polars_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 │
╰───┴───────┴───────╯

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