[Python] How to apply scipy filter in Polars DataFrame

Discussão em 'Python' iniciado por Stack, Março 25, 2025.

  1. Stack

    Stack Membro Participativo

    I'm currently using savgol filter in my DataFrame, which has 3 columns x, y, z With float values of a signal from a micro controller

    in pandas it's straight forward

    df["x"] = savgol_filter(df["x"], 51, 1)
    df["y"] = savgol_filter(df["y"], 51, 1)
    df["z"] = savgol_filter(df["z"], 51, 1)


    how to implement the same in polars

    I tried using this method

    df.with_columns(
    (savgol_filter(df["x"], 51, 1)).alias("x"),
    (savgol_filter(df["y"], 51, 1)).alias("y"),
    (savgol_filter(df["z"], 51, 1)).alias("`"),
    )


    The above code returns Attribute error. AttributeError: 'numpy.ndarray' object has no attribute 'alias'

    Edit: My question is fairly simple, what is the right syntax/method to implement a scipy filters in polars DataFrame?.

    Continue reading...

Compartilhe esta Página