Skip to content

enh: add LazyFrame.pivot #1901

@MarcoGorelli

Description

@MarcoGorelli

This is something I'd quite like to see. In Polars too, but it's easier to implement here 😄

There's an example in the Polars docs about how to do a lazy pivot: https://docs.pola.rs/api/python/stable/reference/dataframe/api/polars.DataFrame.pivot.html

API-wise, we could have:

    def pivot(
        self: Self,
        on: str | list[str],
        *,
        column_names: list[str],
        index: str | list[str] | None = None,
        values: str | list[str] | None = None,
        aggregate_function: Literal[
            "min", "max", "sum", "mean", "median", "len"
        ]
        | None = None,
        separator: str = "_",
    ) -> Self:

This is very similar to DataFrame.pivot, but requires specifying the output column names explicitly so that the computation can stay completely lazy

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions