Listen der Listen in Polaren verschmelzen oder abflachenPython

Python-Programme
Anonymous
 Listen der Listen in Polaren verschmelzen oder abflachen

Post by Anonymous »

Hallo, ich habe einen Polars-Datenframe mit einer Spalte, die Listen von Listen enthält.import polars as pl

df = pl.DataFrame({
"nodes": [[[1], [1,2], []], [[2]], [[1], [2]]]
})
< /code>
shape: (3, 1)
┌───────────────────┐
│ nodes │
│ --- │
│ list[list[i64]] │
╞═══════════════════╡
│ [[1], [1, 2], []] │
│ [[2]] │
│ [[1], [2]] │
└───────────────────┘
< /code>
I want to merge all these sublists into one single list like this:
shape: (3, 1)
┌───────────┐
│ nodes │
│ --- │
│ list[i64] │
╞═══════════╡
│ [1, 1, 2] │
│ [2] │
│ [1, 2] │
└───────────┘
< /code>
I am pretty sure that must be doable pretty easily but I don't find the correct way in the API. Thanks for any help!

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post