Word Clouds with Python
Word clouds, also known as tag clouds or text clouds, are simply visual representations of text. They can be used to create a visual summaries of data such as survey responses, long documents, product reviews, or social media posts.
Word clouds became very popular in the last decades due to its simplicity and modern look. They have been used for advertisement, marketing, and educational purposes as well as just as a decorative element.
How to make a Word Cloud?
Online Generators: A number of online tools are available to create word clouds. They allow you to type words, copy text, or upload a document, to create a word cloud. Some of the most popular are:
Python: It is fairly easy to make word clouds using Python. This offers several advantages over online generators such as
- There is no number of words restriction
- Full control of the customisation features such as colour, font, size, shape, etc.
- There is no need to copy-paste or upload files (especially useful if you want to make a cloud for work).
- Last but not least, it is much more fun!
Word Clouds Using Python
To make some clouds we need one main ingredient: text. The easiest way to get text is by typing it but of course we don’t want to do that. Instead, we can use the following three methods:
- Producing dummy text using the lorem library
- Extracting text from the web using Requests and Beautiful Soup
- Extracting text from a PDF document using pdfminer
Once we have our text ready, we can easily create word-clouds using the Python library wordcloud.
Ok, let’ take a look at the code and then have fun making clouds. As usual you can find this Python Notebook (as well the article and the heart image used to produce these clouds) in my GitHub.