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:

Once we have our text ready, we can easily create word-clouds using the Python library wordcloud.

cloud_pink.png
This cloud was made using the text from the amazing article A short history of stochastic integration and mathematical finance: The early years, 1880–1970 by Robert Jarrow and Philip Protter.

Besides, with the help of  numpy and pillow we can fully customise the shape and colours to create prettier clouds such as this colourful heart.

hear_rainbow
This cloud was made using the text from A short history of stochastic integration and mathematical finance: The early years, 1880–1970 by Robert Jarrow and Philip Protter.

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.


Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

view raw
Word_Cloud.ipynb
hosted with ❤ by GitHub

 

 

Quant Girl

I write about Mathematics, Statistics, Finance, Programming, and the relationships among them. I enjoy learning, listening to music and podcasts, practicing yoga, reading magazines, and watching documentaries.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.