I have a Pandas framework that contains a large number of variables. This can be simplified as:
tempDF = pd.DataFrame({ 'var1': [12,12,12,12,45,45,45,51,51,51],
'var2': ['a','a','b','b','b','b','b','c','c','d'],
'var3': ['e','f','f','f','f','g','g','g','g','g'],
'var4': [1,2,3,3,4,5,6,6,6,7]})
If I wanted to select a subset of the DataFrame (e.g. var2 = 'b' and var4 = 3), I would use:
tempDF.loc[(tempDF['var2']=='b') & (tempDF['var4']==3),:]
However, is it possible to select a subset of the data frame if the matching criteria is stored inside a dict, for example:
tempDict = {'var2': 'b','var4': 3}
It is important that variable names are not predefined, and the number of variables included in the dict is changed.
I was a little puzzled by this, so any suggestions would be greatly appreciated.