Monday, May 15, 2023

Python Word Cloud

 #Use below Simple Python Code to create Word Cloud Chart based on text saved in a TXT File

#Replace File path in below code

#Replace or Add the stop words that you want to remove along standard stop words

#Change the Max words (from current 30) as per your need


from wordcloud import WordCloud, STOPWORDS

import matplotlib.pyplot as plt

file = open(r"C:\Users\Khan\Desktop\stopwords.txt", errors='ignore')

text = file.read()

stopwords = set(STOPWORDS)

stopwords.update(["drink", "now", "wine", "flavor", "flavors"])

wordcloud = WordCloud(max_words=30, stopwords = stopwords, background_color="white").generate(text)

plt.imshow(wordcloud, interpolation='bilinear')

plt.axis("off")

plt.show()

No comments:

Post a Comment