-
-
Save amankharwal/10b02dd2ae278a21cc490eefc7845a58 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
l_t = Most_Positive_text | |
w1_dict = dict() | |
for word in l_t.split(): | |
w= word.strip() | |
if w in STOPWORDS: | |
continue | |
else: | |
w1_dict[w] = w1_dict.get(w,0)+1 | |
w1_dict = {k: v for k, v in sorted(w1_dict.items(), key=lambda item: item[1],reverse=True)} | |
l_t = Most_Negative_text | |
w2_dict = dict() | |
for word in l_t.split(): | |
w= word.strip() | |
if w in STOPWORDS: | |
continue | |
else: | |
w2_dict[w] = w2_dict.get(w,0)+1 | |
w2_dict = {k: v for k, v in sorted(w2_dict.items(), key=lambda item: item[1],reverse=True)} | |
top_10_pos = list(w1_dict.keys())[:10] | |
top_10_neg = list(w2_dict.keys())[:10] | |
plt.subplot(1,2,1) | |
w_c = WordCloud(width=600,height=400,collocations = False,colormap='nipy_spectral').generate(' '.join(top_10_pos)) | |
plt.title('Top 10 Words In Most Positive Tweets',fontsize=19,fontweight='bold') | |
plt.imshow(w_c) | |
plt.axis('off') | |
plt.subplot(1,2,2) | |
w_c = WordCloud(width=600,height=400,collocations = False,colormap='nipy_spectral').generate(' '.join(top_10_neg)) | |
plt.title('Top 10 Words In Most Negative Tweets',fontsize=19,fontweight='bold') | |
plt.imshow(w_c) | |
plt.axis('off') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment