Python word cloud from a html page: Difference between revisions
From wikiluntti
Line 25: | Line 25: | ||
=== The word cloud === | === The word cloud === | ||
WordCloud library is easy to use. It can create svg graphics, but fonts might get mixed. | |||
<pre> | |||
#The word cloud | |||
from wordcloud import WordCloud, STOPWORDS | |||
import matplotlib.pyplot as plt | |||
stopwords = set(STOPWORDS) | |||
#.generate_from_frequencies() | |||
wordcloud = WordCloud(width = 800, height = 800, | |||
background_color ='white', | |||
stopwords = stopwords, | |||
collocations=False, | |||
min_font_size = 10).generate( ' '.join(map(str, bwords))) | |||
</pre> | |||
=== Save in svg format === | === Save in svg format === | ||
== Exercises == | == Exercises == |
Revision as of 23:55, 18 August 2021
Introduction
Analyze html tables using word clouds.
Theory
Fetching the table
Data scraping is easiest using Pandas. BeautifulSoup is an other good option.
Linguistic analyzation
The Finnish language is used, thus Voikko morphological analyzer is used to lemmatize the words into the base format.
sudo apt -y install -y voikko-fi python-libvoikko pip3 install libvoikko
References
https://data.solita.fi/finnish-stemming-and-lemmatization-in-python/
The word cloud
WordCloud library is easy to use. It can create svg graphics, but fonts might get mixed.
#The word cloud from wordcloud import WordCloud, STOPWORDS import matplotlib.pyplot as plt stopwords = set(STOPWORDS) #.generate_from_frequencies() wordcloud = WordCloud(width = 800, height = 800, background_color ='white', stopwords = stopwords, collocations=False, min_font_size = 10).generate( ' '.join(map(str, bwords)))