Oct-30-2019, 08:43 PM
(This post was last modified: Oct-30-2019, 09:12 PM by ichabod801.)
I have written code to help me generate a WordCloud but my boss has asked me to include a frequency list for my data based on a short description. I am trying to get the numbers behind the wordcloud I have generated (ex. award 1957). Can someone help me with what code I would have to add to generate this in addition to the wordcloud.
My code:
My code:
# Python program to generate WordCloud # importing all necessery modules from wordcloud import WordCloud, STOPWORDS import matplotlib.pyplot as plt import pandas as pd # Reads 'short_description' file df = open('PythonTestData.txt') comment_words = ' ' stopwords = set(STOPWORDS) # iterate through the csv file for val in df: # typecaste each val to string val = str(val) # split the value tokens = val.split() # Converts each token into lowercase for i in range(len(tokens)): tokens[i] = tokens[i].lower() for words in tokens: comment_words = comment_words + words + ' ' wordcloud = WordCloud(width=800, height=800, background_color='white', stopwords=stopwords, min_font_size=10).generate(comment_words) # plot the WordCloud image plt.figure(figsize=(8, 8), facecolor=None) plt.imshow(wordcloud) plt.axis("off") plt.tight_layout(pad=0) plt.show()