Created
April 10, 2020 12:10
-
-
Save abhishek-shrm/d0f36e69fc0a39067e6f700b1268b4f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Importing wordcloud for plotting word clouds and textwrap for wrapping longer text | |
from wordcloud import WordCloud | |
from textwrap import wrap | |
# Function for generating word clouds | |
def generate_wordcloud(data,title): | |
wc = WordCloud(width=400, height=330, max_words=150,colormap="Dark2").generate_from_frequencies(data) | |
plt.figure(figsize=(10,8)) | |
plt.imshow(wc, interpolation='bilinear') | |
plt.axis("off") | |
plt.title('\n'.join(wrap(title,60)),fontsize=13) | |
plt.show() | |
# Transposing document term matrix | |
df_dtm=df_dtm.transpose() | |
# Plotting word cloud for each product | |
for index,product in enumerate(df_dtm.columns): | |
generate_wordcloud(df_dtm[product].sort_values(ascending=False),product) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment