Word Cloud using python

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome back to another video you might have probably come across a cloud of words containing words of different sizes in various shapes or in a simple rectangular format this is known as a tag cloud or a word cloud in this tutorial video we will look at how to create word clouds in python and how to give a shape to them before moving forward please take a moment to hit the like button and smash that subscribe button and turn on bell notification so that you don't miss any updates stay tuned what is word cloud word cloud is a data visualization tool for text and are mainly used to visualize the words with high frequency or importance in a text or website each word in the word cloud will be of a different color and size the words with the biggest font size will be the most frequently occurring words okay so now let's head over to jupiter notebook the first thing to do is to install the required libraries now since i've already installed the libraries it will show the requirement is already satisfied the next thing to do is to import the necessary modules so for this i am importing the white cloud module importing matplotlib library to display the plots now we need to import the pandas and numpy library next we need to import the nltk library for removing the stop words in tokenization the stock words are words that do not add much meaning to the sentence and we can remove it from our analysis so now since the libraries are installed let's proceed to import the stock words so we're importing stop words from nltk corpus and we're importing word tokenize from nltk tokenize now let's set the stop words as english stop words to do that stop words equal to set stop words not words english and this will tell the program to select all the stop words in english to see this output we can print the stop words print stop words and there you have a list of all the stop words in english now let's add data to create a word cloud for this example i'm taking a definition of artificial intelligence from the wikipedia so our data will be now that we have the data i'm going to create a function to do some pre-processing on the data such as top border movement tokenization and lowercase conversion to do this i am defining a function data preprocessing define data and the input will be our data and what this will do is lowercase conversion to do that it will take in the data and data dot lower this will convert the data into lower case and then we need to tokenize the data to do that data tokens equal to what tokenize what organize our data the next thing we need to do in a processing is to remove the stock words word for word in data tokens if not word in stopwords so what this function does is it will check for all the words in our data tokens and we will return all the words which are not there in a stock word list and we need to return the process words so this is a function now let's apply preprocessing to our data to do this as you can see this is our original data and this is the process data now that we have processed the text data let's plot the word cloud let's define the figure size i'm giving 10 by 10 and face colors none the face color is used to add a border if none is selected no board is given data processed and we'll do plot dot image show to show the image we want to turn off the axis so i'm typing plot dot axis off and as we can see our word cloud is generated now instead of none if we give a face color for example giving red we will get a red border similarly i can change the size of the figure the figure will be larger we can also change the background color to do that we need to type in the background color background color equal to i'm giving white and it'll give you the word cloud in a white background now i can also save this word cloud as an image to do that i'm first setting the part directory import os os dot change directory i'm setting the path to where i want to save the data i'm setting the path as d drive and now to save the word cloud word cloud dot to file and give a name on png so we are saving it over here and we are running the cell and as you can see the word cloud is saved as a png file the next thing we are going to do is to give a shape for our word cloud so we are going to do the word cloud in the shape to do that first we will import the image library then we'll read the image file as a numpy array file name is brain so we're telling the software to open the image file as a numpy array now that we have read the image file as a numpy array let's create the word cloud password cloud and we'll give a figure size and there you have it a word cloud in the shape of the image now so far we have looked at creating word cloud from data in jupyter notebook now let us look at creating word cloud from the data in a csv file for this i have some codes on artificial intelligence by various authors in an excel file i am going to use this file and create a word cloud from it to do this i need to read the data [Music] understand read excel and to see the codes we can print the codes so this is the data for our word cloud let's apply the processing on this data we are going to process the codes from this data apply data processing now that the data is processed let's combine the different tokens and generate the word cloud from it now let's set the figure size and the face color turning the access off and so you mentioned word cloud and you can see the word cloud now if you make the access as on you can see the axis being also plotted along the word cloud now similarly let's apply a mask to this mask word cloud background color is white and mask as musk let's set the figure size mass world cloud turning the access off and as we can see we have the word cloud with a mask in a white background and similarly let's save this and as we can see mass word cloud is generated now let's generate a transparent background for our mast word cloud to do this i'm copying this code masked word cloud text background color is none and i'm adding a mode gbe as you can see we have a white document now let's save the transparent masked word cloud mast workflow transparent and as we can see we have a transparent word cloud that brings us to the end of this video hope you got an idea about creating word clouds in python let me know your thoughts in the comment section below don't forget to drop a like and share this video if you found it useful thank you for watching and see you in the next video you
Info
Channel: The AI & DS Channel
Views: 157
Rating: 5 out of 5
Keywords: word cloud, wordcloud, wordcloud python, word cloud python, wordcloud using python, how to create word cloud, creating wordcloud, word cloud generation using python, how to make wordcloud, word cloud tutorial, wordcloud tutorial, how to create a word cloud in python, word cloud with python, creating word cloud in python, word cloud python script, word cloud python code, word cloud python tutorial, saving wordcloud, word cloud with shape, word cloud with mask
Id: 4N_exdTyGHk
Channel Id: undefined
Length: 14min 39sec (879 seconds)
Published: Wed Sep 08 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.