Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
from wordcloud import WordCloud, STOPWORDS
import matplotlib.pyplot as plt
import pandas as pd
#CHANGE AS NEEDED
df = pd.read_csv(
"data/computed/cluster/april-21/1-gram-8-clusters.csv", encoding="latin-1")
export_path = 'reports/wordclouds/april-21/'
cluster_no = 8
stopwords = set(STOPWORDS) #need for wordcloud
for i in range(0, cluster_no):
both = df[df['cluster'] == i]
both['text'] = both['text'].apply(lambda x: str(x))
print('printing both wordcloud for cluster no. {}'.format(i))
wordcloud = WordCloud(width=800, height=800,
background_color='white',
stopwords=stopwords,
min_font_size=10).generate(" ".join(both.text))
wordcloud.to_file(export_path + 'cluster_{}_both.png'.format(i))
"""yes = df[(df['Y/N'] == 1) & (df['cluster'] == i)]
#print(yes.head())
print('printing yes wordcloud for cluster no. {}'.format(i))
wordcloud = WordCloud(width=800, height=800,
background_color='white',
stopwords=stopwords,
min_font_size=10).generate(" ".join(yes.text))
wordcloud.to_file(export_path + 'cluster_{}_yes.png'.format(i))
no = df[(df['Y/N'] == 0) & (df['cluster'] == i)]
#print(no.head())
print('printing no wordcloud for cluster no. {}'.format(i))
wordcloud = WordCloud(width=800, height=800,
background_color='white',
stopwords=stopwords,
min_font_size=10).generate(" ".join(no.text))
wordcloud.to_file(
export_path + 'cluster_{}_no.png'.format(i))"""
#if want to display
# plt.figure(figsize=(8, 8), facecolor=None)
# plt.imshow(wordcloud)
# plt.axis("off")
# plt.tight_layout(pad=0)
# plt.show()