I have a Polars dataframe like
df = pl.DataFrame(
{
"tags": ['{"ref":"@1", "area": "livingroom", "type": "elec"}', '{"ref":"@2", "area": "kitchen"}', '{"ref":"@3", "type": "elec"}'],
"name": ["a", "b", "c"],
})
┌────────────────────────────────────────────────────┬──────┐
│ tags ┆ name │
│ --- ┆ --- │
│ str ┆ str │
╞════════════════════════════════════════════════════╪══════╡
│ {"ref":"@1", "area": "livingroom", "type": "elec"} ┆ a │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┤
│ {"ref":"@2", "area": "kitchen"} ┆ b │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┤
│ {"ref":"@3", "type": "elec"} ┆ c │
└────────────────────────────────────────────────────┴──────┘
What I would to do is create a filter function that filters dataframe based on the tags column.
Ie I would like to only be left with rows
where the tags column has an area key and a type key that has a value elec
How can I do that ?
Ideally using the native expressions API but its not vital.
Thanks