Advertisement

Word Cloud with Python Tutorial


Word Cloud with Python Tutorial

 

What is a Word Cloud?

A word cloud is more than a simple graphical representation of textual data. In data science, it plays a major role in analyzing data from different types of applications. A word cloud is a graphical representation of words, i.e. tags, which are used to represent the frequency of entities in a particular data set.

In Data Science, word clouds are mainly used to visualize the most frequent words in a graphical representation to identify keywords of different sizes and colours based on the frequency of the words.





Word Cloud with Python Tutorial:

Hope you now know what word clouds are and why they are used in data analysis. In this section, I’ll walk you through a tutorial on creating a word cloud with Python.


To create a word cloud with the Python programming language, I’ll be using Google Play Store Reviews data which can be easily downloaded below. Now let’s import the necessary Python dataset and libraries and start building a word cloud with Python:


from wordcloud import WordCloud, STOPWORDS 

import matplotlib.pyplot as plt 

import pandas as pd 


df1 = pd.read_csv('five_star_reviews.csv')

df1.head()


RatingReview
05You have to improve the camera performance, an…
15It keeps hanging up completely phone(S10+) and…
25Perfect for virtual conversation. We suggest t…
35A very decent experience i’ve gained using the…
45This app is very good as everyone knows. Here …



The above data is only for 5-star ratings in Google Play Store reviews, now I’m going to import data from 1-star reviews to make the word cloud interesting:

1
df2 = pd.read_csv('one_star_reviews.csv')
2
df2.head()

RatingReview
01Latest update broke the photo taking function….
11It was one of my favourite app. Easy and secur…
21WhatsApp has a major glitch or bug that is hor…
31It was a good app for communication but it is …
41A almost a year passed and the bug I reported …


Now let’s see how to create a word cloud with Python by using the WorldCloud and Matplotlib libraries in Python:

stopwords = set(STOPWORDS) 
words = ''
for review in df1.Review:
    tokens = str(review).split()
    tokens = [i.lower() for i in tokens]
    
    words += ' '.join(tokens) + ' '
    
wordcloud = WordCloud(width = 800, height = 800, 
                background_color ='white', 
                stopwords = stopwords, 
                min_font_size = 10).generate(words) 
  
# plot the WordCloud image                        
plt.figure(figsize = (8, 8), facecolor = None) 
plt.imshow(wordcloud) 
plt.axis("off") 
plt.tight_layout(pad = 0) 
  
plt.show() 

Post a Comment

0 Comments