In [ ]:
import pandas as pd
from wordcloud import WordCloud, STOPWORDS
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import PIL.Image
In [ ]:
text= open('she_walks_in_beauty.txt').read()
print(text)
She walks in beauty, like the night
Of cloudless climes and starry skies;
And all that’s best of dark and bright
Meet in her aspect and her eyes;
Thus mellowed to that tender light
Which heaven to gaudy day denies.

One shade the more, one ray the less,
Had half impaired the nameless grace
Which waves in every raven tress,
Or softly lightens o’er her face;
Where thoughts serenely sweet express,
How pure, how dear their dwelling-place.

And on that cheek, and o’er that brow,
So soft, so calm, yet eloquent,
The smiles that win, the tints that glow,
But tell of days in goodness spent,
A mind at peace with all below,
A heart whose love is innocent!


In [ ]:
#check the stopwords
print(STOPWORDS)
{"can't", 'them', 'against', 'before', 'she', 'as', "what's", "wasn't", 'again', 'ours', 'of', 'were', 'i', 'on', 'with', "couldn't", "he'll", 'same', 'should', 'such', "they're", 'where', 'it', 'he', 'what', 'been', 'this', 'himself', "you're", 'during', "haven't", 'hers', 'its', 'most', 'up', 'under', 'we', 'no', 'and', "that's", "i've", 'after', "don't", 'ever', 'those', "she'll", "shan't", "shouldn't", 'was', 'other', 'your', 'their', "they'd", 'therefore', "aren't", 'is', "won't", 'yours', 'only', 'being', 'any', 'could', 'once', 'all', 'further', 'otherwise', 'else', "hadn't", 'our', 'theirs', "mustn't", 'myself', 'yourselves', "who's", 'does', "we're", 'to', 'however', 'having', 'why', 'not', 'because', 'get', 'too', 'then', "we've", 'which', 'while', 'both', 'me', 'nor', 'here', 'hence', "hasn't", 'more', 'some', 'you', 'can', "i'll", 'there', 'his', 'over', 'herself', 'had', 'who', "she'd", "there's", 'http', 'in', 'would', 'doing', 'about', 'than', 'do', 'him', "he's", 'between', 'cannot', 'shall', "wouldn't", 'a', 'itself', 'ourselves', 'into', 'are', 'since', "weren't", 'they', 'very', 'that', 'down', 'so', "isn't", 'own', 'her', 'below', 'few', 'from', "they've", 'have', "let's", 'also', 'above', 'be', "why's", 'off', "i'd", 'by', "i'm", "she's", 'r', "here's", 'through', "didn't", 'out', 'did', 'themselves', 'ought', 'has', "we'll", "doesn't", 'com', 'just', 'whom', "they'll", 'if', 'how', "you'll", 'these', "where's", 'www', "you've", 'until', 'each', "how's", "he'd", 'like', 'am', "it's", 'or', 'at', 'for', "we'd", "when's", 'when', 'yourself', 'the', 'but', "you'd", 'k', 'an', 'my'}
In [ ]:
#visualize the text
plt.figure(figsize=(8,4))
wc= WordCloud(stopwords=STOPWORDS, colormap='berlin',
              background_color='#e5e5e5').generate(text)
plt.imshow(wc) #imageshow
plt.axis('off')
plt.show()
No description has been provided for this image
In [ ]:
#read the shape
pic_heart = np.array(PIL.Image.open('heart.png'))
In [ ]:
#create a heart shaped word cloud
plt.figure(figsize=(8,8))
wc= WordCloud(colormap='berlin', background_color='white', stopwords=STOPWORDS,
              mask=pic_heart, contour_color='steelblue',
              contour_width=6).generate(text)
plt.imshow(wc)
plt.axis('off')
plt.show()
No description has been provided for this image
In [ ]:
 
In [ ]:
text2= open('python_intro.txt').read()
print(text2)
Python is a programming language that lets you work more quickly and integrate your systems more effectively. These are some of the reasons people who use Python would rather not use anything else. Python can be easy to pick up whether you're a first time programmer or you're experienced with other languages. The following pages are a useful first step to get on your way writing programs with Python! Python is developed under an OSI-approved open source license, making it freely usable and distributable, even for commercial use. Python's license is administered by the Python Software Foundation.
In [ ]:
 
In [ ]:
#check the stopwords
print(STOPWORDS)
{"can't", 'them', 'against', 'before', 'she', 'as', "what's", "wasn't", 'again', 'ours', 'of', 'were', 'i', 'on', 'with', "couldn't", "he'll", 'same', 'should', 'such', "they're", 'where', 'it', 'he', 'what', 'been', 'this', 'himself', "you're", 'during', "haven't", 'hers', 'its', 'most', 'up', 'under', 'we', 'no', 'and', "that's", "i've", 'after', "don't", 'ever', 'those', "she'll", "shan't", "shouldn't", 'was', 'other', 'your', 'their', "they'd", 'therefore', "aren't", 'is', "won't", 'yours', 'only', 'being', 'any', 'could', 'once', 'all', 'further', 'otherwise', 'else', "hadn't", 'our', 'theirs', "mustn't", 'myself', 'yourselves', "who's", 'does', "we're", 'to', 'however', 'having', 'why', 'not', 'because', 'get', 'too', 'then', "we've", 'which', 'while', 'both', 'me', 'nor', 'here', 'hence', "hasn't", 'more', 'some', 'you', 'can', "i'll", 'there', 'his', 'over', 'herself', 'had', 'who', "she'd", "there's", 'http', 'in', 'would', 'doing', 'about', 'than', 'do', 'him', "he's", 'between', 'cannot', 'shall', "wouldn't", 'a', 'itself', 'ourselves', 'into', 'are', 'since', "weren't", 'they', 'very', 'that', 'down', 'so', "isn't", 'own', 'her', 'below', 'few', 'from', "they've", 'have', "let's", 'also', 'above', 'be', "why's", 'off', "i'd", 'by', "i'm", "she's", 'r', "here's", 'through', "didn't", 'out', 'did', 'themselves', 'ought', 'has', "we'll", "doesn't", 'com', 'just', 'whom', "they'll", 'if', 'how', "you'll", 'these', "where's", 'www', "you've", 'until', 'each', "how's", "he'd", 'like', 'am', "it's", 'or', 'at', 'for', "we'd", "when's", 'when', 'yourself', 'the', 'but', "you'd", 'k', 'an', 'my'}
In [ ]:
 
In [ ]:
#visualize the text
plt.figure(figsize=(8,4))
wc= WordCloud(stopwords=STOPWORDS, colormap='cool',
              background_color='yellow').generate(text2)
plt.imshow(wc) #imageshow
plt.axis('off')
plt.show()
No description has been provided for this image
In [ ]:
#read the shape
pic_python = np.array(PIL.Image.open('python.png'))
In [ ]:
#create a python shaped word cloud
plt.figure(figsize=(8,8))
wc= WordCloud(colormap='cool', background_color='white', stopwords=STOPWORDS,
              mask=pic_python, contour_color='steelblue',
              contour_width=6).generate(text2)
plt.imshow(wc)
plt.axis('off')
plt.show()
No description has been provided for this image
In [ ]: