Python Basic Wordcloud

This exercise is using Jupyter Notebook. For the enviroment I’m using Anaconda. Learning to manage the libraries and versions can be just as complicated as the code. So with Anaconda installed, create an environment called wordcloud .

conda create -n wordcloud python=3.8 anaconda
conda activate wordcloud

Now install some modules – nb_conda, wordcloud,

conda install -n wordcloud -c conda-forge nb_conda
conda install  -n wordcloud -c conda-forge wordcloud 

Start “jupyter notebook” and I’m seeing a Conda tab and the current environment is “wordcloud”

Now create a New Notebook in the wordcloud environment.

Here is the code below to make a simple wordcloud (actually based on what I learned from Zolzaya Luvsandori )

import matplotlib.pyplot as plt
%matplotlib inline
from wordcloud import WordCloud, STOPWORDS
buzzwords  = "Ruby Elasticsearch Apache Nginx WordPress Vmware Php HP Business_Intelligence Windows Canvas Studynet SUSE Solaris Qualys Sophos Cacti webmin Postix Exchange IDM ADFS Oracle mySQL Office365 Anti_virus DNS Wifi TCP Adobe"
wordcloud = WordCloud(width = 3000, height = 2000, random_state=1, background_color='turquoise', colormap='Pastel1', collocations=False, stopwords = STOPWORDS).generate(text)
plt.figure(figsize=(20, 15))
plt.imshow(wordcloud) 
plt.axis("off");
wordcloud.to_file("workcloud.png")

You can play with this, for example give frequencies to values using a dictionary (using generate_from_frequences(text))

text = { "windows_10":300, "CentOS":200, "Solaris":5, "Ubuntu":5, "Debian":40, }
wordcloud = WordCloud(width = 3000, height = 2000, random_state=1, relative_scaling=0.2,background_color='white', colormap='Set2', collocations=False,stopwords = STOPWORDS).generate_from_frequencies(text)