Spec-Zone.ru › Nushell

polars list-contains for dataframe

Checks if an element is contained in a list.

Signature

> polars list-contains {flags} (element)

Parameters

  • element: Element to search for in the list.

Input/output types:

input output
polars_expression polars_expression
polars_selector polars_expression

Examples

Returns boolean indicating if a literal element was found in a list column

> let df = [[a]; [[a,b,c]] [[b,c,d]] [[c,d,f]]] | polars into-df -s {a: list<str>};
                let df2 = $df | polars with-column [(polars col a | polars list-contains (polars lit a) | polars as b)] | polars collect;
                $df2.b
╭───┬───────╮
│ # │   b   │
├───┼───────┤
│ 0 │ true  │
│ 1 │ false │
│ 2 │ false │
╰───┴───────╯

Returns boolean indicating if an element from another column was found in a list column

> let df = [[a, b]; [[a,b,c], a] [[b,c,d], f] [[c,d,f], f]] | polars into-df -s {a: list<str>, b: str};
                let df2 = $df | polars with-column [(polars col a | polars list-contains b | polars as c)] | polars collect;
                $df2.c
╭───┬───────╮
│ # │   b   │
├───┼───────┤
│ 0 │ true  │
│ 1 │ false │
│ 2 │ true  │
╰───┴───────╯

Returns boolean indicating if an element from another expression was found in a list column

> let df = [[a, b]; [[1,2,3], 4] [[2,4,1], 2] [[2,1,6], 3]] | polars into-df -s {a: list<i64>, b: i64};
                let df2 = $df | polars with-column [(polars col a | polars list-contains ((polars col b) * 2) | polars as c)] | polars collect;
                $df2.c
╭───┬───────╮
│ # │   b   │
├───┼───────┤
│ 0 │ false │
│ 1 │ true  │
│ 2 │ true  │
╰───┴───────╯

Copyright © 2019–2026 The Nushell Project DevelopersLicensed under the MIT License.
https://www.nushell.sh/commands/docs/polars_list-contains.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API