As I’ve been preparing for different Python talks about data science techniques I came across this cool feature you can do with Word Clouds in Python! Word clouds can be very useful when showing what the most important sentiments of a group of people are. They also, well, look pretty!
I played around with the wordcloud generator in python and came up with some cool images!
In order to get started you must import several packages. The easiest way for me was to use pip:
- This is one of pythons imaging library. It is a forked version of PIL and is now the only one kept up to date. IMPORTANT: If you already have PIL installed, you will have to uninstall it before installing Pillow.
- Numpy is an extremely important package for scientific computing. It is useful for creating N dimensional arrays, linear algebra, Fourier transform, and has random number capabilities.
- Matplotlib is a 2d plotting library and another important tool that is useful in scientific computing and data science.
- This is word cloud generator that sets up the word cloud in a specific shape and then fills in words based on the frequency of different words. The larger the word, the more often it occurs!
In order to use your own image, you need to find an image that is filled in with black. If you don’t, only the outline will fill in with words. and then you can’t really see the image shape. Now, I really like minions, so I tried to different images to see how they would turn out. A minion might not be the best shape, but in the second one you can definitely see a better outline!
I also did it with a puppy, and this one came out great! As you can see, the same words came out the largest in all of them!