image_output_2.png image_output_1.png
from PIL import Image

from wordcloud import WordCloud, STOPWORDS, ImageColorGenerator

import matplotlib.pyplot as plt

import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

df = pd.read_csv('../input/source-based-news-classification/news_articles.csv')

df.isnull().sum()

df = df.dropna()

text = ' '.join(df['text_without_stopwords'])

wordcloud = WordCloud().generate(text)
plt.axis('off')

wordcloud = WordCloud(max_font_size=50, max_words=10, background_color='white').generate(text)
plt.axis('off')

stopwords = set(STOPWORDS)
wordcloud = WordCloud(width=3000, height=2000, random_state=1, background_color='black', colormap='Set2', collocations=False, stopwords=STOPWORDS).generate(text)
plt.axis('off')

stopwords = set(STOPWORDS)
mask = np.array(Image.open('../input/input-img/download1.png'))
wordcloud = WordCloud(stopwords=stopwords, background_color='white', max_words=1000, mask=mask, contour_color='#023075', contour_width=3, colormap='rainbow').generate(' '.join(df['text_without_stopwords']))
plt.axis('off')

stopwords = set(STOPWORDS)
mask = np.array(Image.open('../input/input-img/Twitter.png'))
wordcloud = WordCloud(stopwords=stopwords, background_color='white', max_words=1000, mask=mask).generate(' '.join(df['text_without_stopwords']))
plt.figure()
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis('off')
plt.savefig('twitter.png', format='png')
plt.show()