pythonsframe

How do i remove this error?


I am trying to count the number of times the word 'awesome' has been used in the dictionary and use that function in order to apply it on an SFrame data. but i keep getting an error stating -local variable 'aw_count' referenced before assignment the code is something like this::

def awesome_count(word_count):
    if 'awesome' in word_count:
        aw_count = word_count['awesome']
    return aw_count;

products['awesome'] = products['word_count'].apply(awesome_count)

Solution

  • Try

    def awesome_count(word_count):
        aw_count = 0
        if 'awesome' in word_count:
            aw_count = word_count['awesome']
        return aw_count;
    

    You will get this error you stated if there are no 'awesome' in word_count