I have a dictionary with keys of itemsets and values of their counts. I want to count how many times the itemsets appear in a dataframe (as an exact match). The dataframe has ~10k rows
Dictionary of 1st itemsets (dict_of_items):
{'apple','banana','pear'}: 0,
{'banana', 'orange', 'squash'}: 0
Dataframe of 2nd itemsets (df):
Index | basket
1 | ['apple','banana',pear']
2 | ['banana']
3 | ['banana', 'orange','squash']
4 | ['apple','banana',pear']
...
Desired output (where the dictionary's values is the actual count):
{'apple','banana','pear'}: 2,
{'banana', 'orange', 'squash'}: 1
I have tried in and .iterrows(), but the values remain 0, e.g.:
for item in dict_of_items:
if item in df['basket']:
dict_of_item[item] += 1