[Python] Polars alternative solution to using map_groups with with_columns

Discussão em 'Python' iniciado por Stack, Fevereiro 19, 2025.

  1. Stack

    Stack Membro Participativo

    I think after the recent update of Polars (version 0.20.7), it stopped supporting the use of map_groups with with_columns I got a Type Error stating

    TypeError: cannot call `map_groups` when grouping by an expression


    I am trying to Group By a column called Product Number and fill the null values using backward strategy for this Group By.

    The code I wrote was.

    df1 = (
    df1
    .group_by(['Product Number'])
    .map_groups(lambda df1: (
    df1
    .with_columns(
    df1['New Date'].fill_null(strategy='backward').alias('New Date1')
    )
    )
    )
    )


    Is there alternate solution which supports grouping with with_columns ?

    Continue reading...

Compartilhe esta Página