Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Polars join on array items without explode/groupby

$
0
0

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"}]]    }]})

Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>