I have a dataframe in which each row shows one transaction and items within that transactions. Here is how my dataframe looks like
itemList
A,B,C
B,F
G,A
...
I want to find the frequency of each item (how many times it appeared in the transactions. I have defined a dictionary and try to update its value as shown below
dict ={}
def update(itemList):
#Update the value of each item in the dict
df.itemList.apply(lambda x: update(x))
As apply
function gets executed for multiple row at the same time, multiple rows try to update the values in dict
at the same time and it's causing an issue. How can I make sure multiple updated to dict
does not cause any issue?