Word Cloud Generation in Python
Let us see how to generate a word cloud in python in any shape as desired.
Step 1: Importing the necessary library and packages
Note: Sometimes one can receive an error that states “No module named ‘wordcloud’. To correct the error run the following command in the command prompt to install wordcloud.
Step 2:
To obtain a custom shape for the word cloud, look for an image that one wishes to use as a mask. The image that I have used is that of the Indian Map of 450x450 pixels.
Step 3:
Download the image and save it as a ‘png’ file. Store the image in the same folder as that of the python notebook.
Step 4: Text data for the word cloud
I have created a list called ‘sentence’ containing different sentences on which the word cloud will be built
Step 4: The code to creating the word cloud
The output will display as:
The entire code for the above process is below: