This question is based on another question I asked, where I didn't cover the problem entirely: Pandas - check if a string column contains a pair of strings
This is a modified version of the question.
I have two dataframes :
df1 = pd.DataFrame({'consumption':['squirrel ate apple', 'monkey likes apple',
'monkey banana gets', 'badger gets banana', 'giraffe eats grass', 'badger apple loves', 'elephant is huge', 'elephant eats banana tree', 'squirrel digs in grass']})
df2 = pd.DataFrame({'food':['apple', 'apple', 'banana', 'banana'],
'creature':['squirrel', 'badger', 'monkey', 'elephant']})
The goal is to test if df.food:df.creature pairs are present in df1.consumptions.
The expected answer for this test in the above example would be :
['True', 'False', 'True', 'False', 'False', 'True', 'False', 'True', 'False']
The pattern is:
squirrel ate apple = True since squirrel and apple is a pair. monkey likes apple = False since monkey and apple is not a pair we are looking for.
I was thinking of constructing a dictionary of dataframes of the pair-values where each dataframe would be for one creature for e.g.squirrel, monkey etc. and then using np.where to create a boolean expression and perform a str.contains.
Not sure if that is the easiest way.
