polars explode for lazyframe
Explodes a dataframe or creates a explode expression.
Signature
> polars explode {flags} ...rest
Flags
-
--empty-as-null: Explode an empty list into anull -
--keep-nulls: Explode anullinto anull
Parameters
-
...rest: A polars selector or columns to explode, only applicable for dataframes
Input/output types:
| input | output |
|---|---|
| polars_expression | polars_expression |
| polars_dataframe | polars_dataframe |
| polars_lazyframe | polars_lazyframe |
Examples
Explode the specified dataframe
> [[id name hobbies]; [1 Mercy [Cycling Knitting]] [2 Bob [Skiing Football]]]
| polars into-df
| polars explode hobbies
| polars collect
| polars sort-by [id, name]
╭───┬────┬───────┬──────────╮
│ # │ id │ name │ hobbies │
├───┼────┼───────┼──────────┤
│ 0 │ 1 │ Mercy │ Cycling │
│ 1 │ 1 │ Mercy │ Knitting │
│ 2 │ 2 │ Bob │ Skiing │
│ 3 │ 2 │ Bob │ Football │
╰───┴────┴───────┴──────────╯
Select a column and explode the values
> [[id name hobbies]; [1 Mercy [Cycling Knitting]] [2 Bob [Skiing Football]]] | polars into-df | polars select (polars col hobbies | polars explode) ╭───┬──────────╮ │ # │ hobbies │ ├───┼──────────┤ │ 0 │ Cycling │ │ 1 │ Knitting │ │ 2 │ Skiing │ │ 3 │ Football │ ╰───┴──────────╯
Copyright © 2019–2026 The Nushell Project DevelopersLicensed under the MIT License.
https://www.nushell.sh/commands/docs/polars_explode.html