3

a follow up from Polars lazyframe - add fields from other lazyframe as struct without a `collect`.

I now want to join on array items. Currently the only way i know of doing this would be to first explode the array, perform the join, do a groupby, then collect back as a list. I'm hoping there is a more concise alternative.

companies = pl.DataFrame({
    "id": [1],
    "name": ["google"],
    "industry": [1001]
}).lazy()

industries = pl.DataFrame({
    "id": [1001],
    "name": ["tech"],
    "sectors": [[10011, 10012]]
}).lazy()

sectors = pl.DataFrame({
    "id": [10011, 10012],
    "name": ["software", "hardware"],
}).lazy()

expected = pl.DataFrame({
    "id": [1],
    "name": ["polars"],
    "industry": [{
        "name": "tech",
        "sectors": [[{"name": "software"}, {"name": "hardware"}]]
    }]
})
Cory Grinstead
  • 511
  • 3
  • 16

0 Answers0