I have a dictionary containing several pandas masks as strings for a specific dataframe, but I can't find a way to use those masks.
Here is a short reproducible example :
df = pd.DataFrame({'age' : [10, 24, 35, 67], 'strength' : [0 , 3, 9, 4]})
masks = {'old_strong' : "(df['age'] >18) & (df['strength'] >5)",
'young_weak' : "(df['age'] <18) & (df['strength'] <5)"}
And I would like to do something like :
df[masks['young_weak']]
But since the mask is a string I get the error
KeyError: "(df['age'] <18) & (df['strength] <5)"