Spec-Zone.ru › Polars

polars.LazyFrame.explode

LazyFrame.explode(
    columns: ColumnNameOrSelector | Iterable[ColumnNameOrSelector],
    *more_columns: ColumnNameOrSelector,
    empty_as_null: bool = <object object>,
    keep_nulls: bool = True,
) → LazyFrame

Explode the DataFrame to long format by exploding the given columns.

engine:In MemoryStreamingDistributed
Parameters:
columns

Column names, expressions, or a selector defining them. The underlying columns being exploded must be of the List or Array data type.

*more_columns

Additional names of columns to explode, specified as positional arguments.

empty_as_null

Explode an empty list/array into a null.

keep_nulls

Explode a null list/array into a null.

Examples

>>> lf = pl.LazyFrame(
...     {
...         "letters": ["a", "a", "b", "c"],
...         "numbers": [[1], [2, 3], [4, 5], [6, 7, 8]],
...     }
... )
>>> lf.explode("numbers", empty_as_null=False).collect()
shape: (8, 2)
┌─────────┬─────────┐
│ letters ┆ numbers │
│ ---     ┆ ---     │
│ str     ┆ i64     │
╞═════════╪═════════╡
│ a       ┆ 1       │
│ a       ┆ 2       │
│ a       ┆ 3       │
│ b       ┆ 4       │
│ b       ┆ 5       │
│ c       ┆ 6       │
│ c       ┆ 7       │
│ c       ┆ 8       │
└─────────┴─────────┘

© 2020 Ritchie Vink
© 2022 Polars contributors
Licensed under the MIT License.
https://docs.pola.rs/api/python/stable/reference/lazyframe/api/polars.LazyFrame.explode.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API