Skip to content

Add example to contains #20581

Open
Open
@jason-ivey

Description

Description

The contains documentation for contains, as well as many of the trait impls, is lacking at https://docs.rs/polars/latest/polars/prelude/trait.StringNameSpaceImpl.html#method.contains

Here is an example I made:

use polars::prelude::*;

fn main() {
    let mut df = DataFrame::new(
        vec![
            Column::new(
                "A".into(),
                ["foo", "bar", "foobar", "foo"],
            ),
            Column::new(
                "B".into(),
                ["bar", "foobar", "foo", "bar"],
            ),
        ]
    )
    .unwrap();

    let selected_and_filtered = df.filter(
        &df.column("A")
            .unwrap()
            .str()
            .unwrap()
            .contains(
                "foo",
                true
            )
            .unwrap()
    );

    println!("{:?}", selected_and_filtered);
}

Link

No response

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions