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

Select all columns with alphanumeric names (eg: only letters). Matching column names cannot contain *any* non-alphanumeric characters. Note that the definition of "alphanumeric" consists of all valid Unicode alphanumeric characters by default; this can be changed by setting `ascii_only=true`.

Signature

> polars selector alphanumeric {flags}

Flags

  • --ascii-only, -a: Indicate whether to consider only ASCII alphanumeric characters, or the full Unicode range of valid letters (accented, idiographic, etc).
  • --ignore-spaces, -s: Indicate whether to ignore the presence of spaces in column names; if so, only the other (non-space) characters are considered.

Input/output types:

inputoutput
anypolars_selector

Examples

Select columns with alphanumeric names.

>
                {
                    "1st_col": [100, 200, 300],
                    "flagged": [true, false, true],
                    "00prefix": ["01:aa", "02:bb", "03:cc"],
                    "last col": ["x", "y", "z"],
                } |
                polars into-df --as-columns |
                polars select (polars selector alphanumeric) |
                polars sort-by 00prefix flagged |
                polars collect

╭───┬─────────┬──────────╮
│ # │ flagged │ 00prefix │
├───┼─────────┼──────────┤
│ 0 │ true    │ 01:aa    │
│ 1 │ false   │ 02:bb    │
│ 2 │ true    │ 03:cc    │
╰───┴─────────┴──────────╯

Select columns with alphanumeric names ignoring spaces.

>
                {
                    "1st_col": [100, 200, 300],
                    "flagged": [true, false, true],
                    "00prefix": ["01:aa", "02:bb", "03:cc"],
                    "last col": ["x", "y", "z"],
                } |
                polars into-df --as-columns |
                polars select (polars selector alphanumeric --ignore-spaces) |
                polars sort-by 00prefix 'last col' flagged |
                polars collect

╭───┬─────────┬──────────┬──────────╮
│ # │ flagged │ 00prefix │ last col │
├───┼─────────┼──────────┼──────────┤
│ 0 │ true    │ 01:aa    │ x        │
│ 1 │ false   │ 02:bb    │ y        │
│ 2 │ true    │ 03:cc    │ z        │
╰───┴─────────┴──────────┴──────────╯

Select all columns except for those with alphanumeric names.

>
                {
                    "1st_col": [100, 200, 300],
                    "flagged": [true, false, true],
                    "00prefix": ["01:aa", "02:bb", "03:cc"],
                    "last col": ["x", "y", "z"],
                } |
                polars into-df --as-columns |
                polars select (polars selector alphanumeric | polars selector not) |
                polars sort-by '1st_col' 'last col' |
                polars collect

╭───┬─────────┬──────────╮
│ # │ 1st_col │ last col │
├───┼─────────┼──────────┤
│ 0 │     100 │ x        │
│ 1 │     200 │ y        │
│ 2 │     300 │ z        │
╰───┴─────────┴──────────╯

Select all columns except for those with alphanumeric names, ignoring spaces.

>
                {
                    "1st_col": [100, 200, 300],
                    "flagged": [true, false, true],
                    "00prefix": ["01:aa", "02:bb", "03:cc"],
                    "last col": ["x", "y", "z"],
                } |
                polars into-df --as-columns |
                polars select (polars selector alphanumeric --ignore-spaces | polars selector not) |
                polars collect

╭───┬─────────╮
│ # │ 1st_col │
├───┼─────────┤
│ 0 │     100 │
│ 1 │     200 │
│ 2 │     300 │
╰───┴─────────╯