polars selector ends-with

For expression.

Select columns that end with the given substring(s).

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

Parameters

  • ...rest: Select columns that end with the given substring(s).

Input/output types:

input output
any polars_selector

Examples

Match columns ending with a ‘z’

> {
        "foo": ["x", "y"],
        "bar": [123, 456],
        "baz": [2.0, 5.5],
        "zap": [false, true],
    } |
    polars into-df --as-columns |
    polars select (polars selector ends-with z) |
    polars sort-by baz |
    polars collect
╭───┬──────╮
│ # │ baz  │
├───┼──────┤
│ 0 │ 2.00 │
│ 1 │ 5.50 │
╰───┴──────╯

Match columns ending with either the letter ‘z’ or ‘r’

> {
        "foo": ["x", "y"],
        "bar": [123, 456],
        "baz": [2.0, 5.5],
        "zap": [false, true],
    } |
    polars into-df --as-columns |
    polars select (polars selector ends-with z r) |
    polars sort-by bar baz |
    polars collect
╭───┬─────┬──────╮
│ # │ bar │ baz  │
├───┼─────┼──────┤
│ 0 │ 123 │ 2.00 │
│ 1 │ 456 │ 5.50 │
╰───┴─────┴──────╯

Match columns ending with except the letter ‘z’

> {
        "foo": ["x", "y"],
        "bar": [123, 456],
        "baz": [2.0, 5.5],
        "zap": [false, true],
    } |
    polars into-df --as-columns |
    polars select (polars selector ends-with z | polars selector not) |
    polars sort-by foo bar zap |
    polars collect
╭───┬─────┬─────┬───────╮
│ # │ foo │ bar │  zap  │
├───┼─────┼─────┼───────┤
│ 0 │ x   │ 123 │ false │
│ 1 │ y   │ 456 │ true  │
╰───┴─────┴─────┴───────╯

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