I am trying to assign the nested dictionaries and I am using:
word_freq_dict = {word: {‘spam’: 0, ‘ham’: 0}}
where I am looping over each word - so I am not using a nice key label but a variable. I don’t know if that is the issue as dictionaries are new to me.
I am getting this error: TypeError: unhashable type: ‘list’
I remember to struggle with the first for loop, with that strange “iterrows()” that I’ve never seen before.
Check if you coded correctly these phyton commands:
In the first for loop you’ll iterate over the data frame rows.
e.g. “for row_i in data_frame.iterrows():”
In the second loop you’ll iterate over the elements (words) of a specific column which contains the lists of words.
e.g. “for word in row_i[‘column_name’]:”
Now that you get word by word, check if it is already in the dict.
e.g. “if word not in dict:”
Try to compare to your code and tell me the results.
Hi @Tom_Pham
Actually if you expand word_freq_dict, dictionary the words are keys and the number of times those words occur in either spam or ham are values.
In python to get the names of keys of a dict you use .keys() which is we need in this case.
In order to get those values we use .items().
For further information please refer python dictionaries, there are many good articles online.