Wie flache ich die Elemente einer Spalte der Typlistenliste so, dass es sich um eine Spalte mit Elementen vom Typ TyplisPython

Python-Programme
Anonymous
 Wie flache ich die Elemente einer Spalte der Typlistenliste so, dass es sich um eine Spalte mit Elementen vom Typ Typlis

Post by Anonymous »

Betrachten Sie das folgende Beispiel: < /p>
import polars as pl

pl.DataFrame(pl.Series("x", ["1, 0", "2,3", "5 4"])).with_columns(
pl.col("x").str.split(",").list.eval(pl.element().str.split(" "))
)
< /code>
shape: (3, 1)
┌────────────────────┐
│ x │
│ --- │
│ list[list[str]] │
╞════════════════════╡
│ [["1"], ["", "0"]] │
│ [["2"], ["3"]] │
│ [["5", "4"]] │
└────────────────────┘
< /code>
I want to flatten the elements of the column, so instead of being a nested list, the elements are just a list:
shape: (3, 1)
┌────────────────┐
│ x │
│ --- │
│ list[str] │
╞════════════════╡
│ ["1", "", "0"] │
│ ["2", "3"] │
│ ["5", "4"] │
└────────────────┘
< /code>
How do I do that?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post