Filtering polars using a dictionary
I work on python with polars. I have: A dataframe df with columns mc1 and mc2 and A dictionary dico. I would like to filter on df to keep only the rows for which mc1 is an existing key of dico and dico[mc1] == mc2. Is it possible? I firstly tried something like this: import polars as pl import numpy as np df = pl.DataFrame({'mc1':[1,2,3,4], 'mc2':[5,6,7,8]}) dico = {1:5,2:2,4:8} df.filter(pl.col('mc1').is_in(dico.keys()) & (dico[pl.col('mc1')] == pl.col('mc2'))) But it didn't work. I also tried to produce a list of booleans indicating which row to keep, like it would work using pandas, doing t
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.