[Python] polars - no attribute 'extract_many'

Discussão em 'Python' iniciado por Stack, Maio 6, 2025.

  1. Stack

    Stack Membro Participativo

    Trying this in Polars 0.20.23 but getting any error.

    import polars as pl

    # Sample data
    data = {
    "text": [
    "Year: 2020, Month: January",
    "Year: 2021, Month: February",
    "Year: 2022, Month: March",
    "Year: 2023, Month: April"
    ]
    }

    # Create a Polars DataFrame
    df = pl.DataFrame(data)

    # Define a regular expression pattern to extract year and month
    pattern = r"Year: (\d{4}), Month: (\w+)"

    # Use extract_many to extract year and month
    df_extracted = df.with_columns(
    pl.col("text").str.extract_many(pattern).alias("year_month")
    )

    # Display the DataFrame with extracted values
    print(df_extracted)



    error

    AttributeError: 'ExprStringNameSpace' object has no attribute 'extract_many'


    What am I doing wrong?

    Continue reading...

Compartilhe esta Página