Is there a way to automate the filtering process in pandas based on the columns and list of associated values the columns are supposed to take?
Please, see the example here:
import pandas as pd
import seaborn as sns
df = sns.load_dataset('tips')
columns = ['sex']
values = ['Female']
df.query(@columns in @values)
columns2 = ['sex', 'smoker']
values2 = ['Male', 'Yes']
df.query(@columns2 in @values2)
Of course, this does not work but is there a way to do so?
The point is that the solution should be generalized as the length of the lists may differ.