from wordcloud import WordCloud, STOPWORDS my_words = {'python': 20, 'machine learning': 10, 'data science': 5, 'big data': 3, 'analysis': 8} wordcloud = WordCloud(width = 800, height = 800, background_color ='white', stopwords = STOPWORDS, min_font_size = 10).generate_from_frequencies(my_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()
from wordcloud import WordCloud, STOPWORDS import pandas as pd df = pd.read_csv('data.csv', header = None) text = '' for i in range(len(df)): text += str(df.loc[i,0]) wordcloud = WordCloud(width = 800, height = 800, background_color ='white', stopwords = STOPWORDS, min_font_size = 10).generate(text) # plot the WordCloud image plt.figure(figsize = (8, 8), facecolor = None) plt.imshow(wordcloud) plt.axis("off") plt.tight_layout(pad = 0) plt.show()In this example, we read in a large body of text from a CSV file, then use `fit_words()` to generate a word cloud visualization of the most commonly occuring words in the text. The package library used in these examples is the `wordcloud` library.