polars selector matches

For expression.

Select all columns that match the given regex pattern.

warning This command requires a plugin The polars selector matches 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 matches {flags} (pattern)

Parameters

Input/output types:

input output
any polars_selector

Examples

Match column names containing an ‘a’, preceded by a character that is not ‘z’

>
                {
                    "foo": ["x", "y"],
                    "bar": [123, 456],
                    "baz": [2.0, 5.5],
                    "zap": [0, 1],
                } |
                polars into-df --as-columns |
                polars select (polars selector matches "[^z]a") |
                polars sort-by bar baz |
                polars collect

╭───┬─────┬──────╮
│ # │ bar │ baz  │
├───┼─────┼──────┤
│ 0 │ 123 │ 2.00 │
│ 1 │ 456 │ 5.50 │
╰───┴─────┴──────╯

Do not match column names ending in ‘R’ or ‘z’ (case-insensitively)

>
                {
                    "foo": ["x", "y"],
                    "bar": [123, 456],
                    "baz": [2.0, 5.5],
                    "zap": [0, 1],
                } |
                polars into-df --as-columns |
                polars select (polars selector matches "(?i)R|z$" | polars selector not) |
                polars sort-by foo zap |
                polars collect

╭───┬─────┬─────╮
│ # │ foo │ zap │
├───┼─────┼─────┤
│ 0 │ x   │   0 │
│ 1 │ y   │   1 │
╰───┴─────┴─────╯

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