def word_count(): file1 = open("gram.txt", "r") a = file1.read() b = TextBlob(a) words = b.word_counts() print(words)
tweets = tweets + tweet_data[e]['text'] #convine all your string or tweets, will be used later in WordCloud function textbird_tb = TextBlob(tweets) undesired_words = ["hi", "bye", "interesting", "goodnight", "spider", "fear"] filtered_dictionary = {} filtered_words[words] = count for word in textbird_tb.words: if(len(word) < 2): continue elif( not word.isalpha()): continue elif(word in undesired_words): #the continue means that if the condition is not met, the elif condition will be broken and it will go back to the beginning of the for loop. continue filtered_dictionary['word'] = textbird_tb.word_counts(word) #Set up you HISTOGRAM plt.his(polarity, bins = [-1.1, -.75, -.5, -.25, 0, .25, .5, .75, 1.1]) plt.xlabel('Polarity') plt.ylabel('Frequency') plt.title('Polarity vs Frequency') plt.axis([-1.1, 1.1, 0, 100]) #describes how high the x and y axis will go. X is first and Y is after. plt.grid(True) plt.show() word_Cloud = WordCloud().generate_from_frequencies(filtered_dictionary) plt.imshow(word_Cloud, interpolation = "bilinear") plt.axis("off") plt.show