I have a dictionary that can take any length, for example, this one:
dic = {'A':'Rome','B':'Japan','C':'EUA'}
and I want to build a function do filter a dataframe using the dict above as parameter, like this:
def filter(dic, df):
for k,v in dic.items():
x=df[(df[k]==v) & (df[k]==v) & (df[k]==v)]
return x
If I had to hard code the filter above would be:
df[(df['A']=='Rome') & (df['B']=='Japan') & (df['C']=='EUA')]
The problem I am facing:
The dictionary doesn't have a fixed length so the number of parameter will change every time.
The code above is not iterating correctly over the dictionary
How can I make that filter function work?