I'm learning to know how Python Dictionaries work and is writing a small program to know if the word awesome in the word count column, then it should return me the value.
However, it is giving me the following error:
TypeError: argument of type 'type' is not iterable
My word_count column is like below:
{'and': 5, 'stink': 1, 'because': 2}
{'awesome': 3, 'bad': 2}
{'mac': 5, 'awesome': 1}
I have created this function:
def awesome_count(self):
if 'awesome' in dict:
return dict['awesome']
else:
return 0
after then, I'm using apply function to get the count, but getting an error:
products['awesome'] = products['word_count'].apply(awesome_count)
Expecting the following answer:
0,3,1 i.e number of times awesome is present
if 'awesome' in dict: return dict['awesome']Where is dict defined?dictshould be the member of your class that you want to look at.selfparameter for? How isdictdefined? What exactly are you trying to do.