[Python] Polars Pandas-like groupby save to files by each value

Discussão em 'Python' iniciado por Stack, Abril 16, 2025.

  1. Stack

    Stack Membro Participativo

    Boiling down a bigger problem to its essentials, I would like to do this:

    import numpy as np
    import pandas as pd

    df = pd.DataFrame({'a': np.random.randint(0, 5, 1000), 'b': np.random.random(1000)})

    for aval, subdf in df.groupby('a'):
    subdf.to_parquet(f'/tmp/{aval}.parquet')


    in Polars using LazyFrame:

    import numpy as np
    import pandas as pd
    import polars as pl

    df = pd.DataFrame({'a': np.random.randint(0, 5, 1000), 'b': np.random.random(1000)})

    lf = pl.LazyFrame(df)
    # ???


    I would like to be able to control the name of the output files in a similar way.

    Thanks!

    Continue reading...

Compartilhe esta Página