Tagged: Crash Course, Google, Python, Word Cloud
- This topic has 0 replies, 1 voice, and was last updated 2 years, 4 months ago by
Abhishek Tyagi.
-
AuthorPosts
-
-
April 8, 2020 at 7:05 pm #264
Abhishek Tyagi
Keymasterhttps://github.com/AbhishekTyagi404/Word-Cloud-Python
Word Cloud is a data visualization technique used for representing text data in which the size of each word indicates its frequency or importance. Significant textual data points can be highlighted using a word cloud. Word clouds are widely used for analyzing data from social network websites.
# Here are all the installs and imports you will need for your word cloud script and uploader widget
!pip install wordcloud
!pip install fileupload
!pip install ipywidgets
!jupyter nbextension install –py –user fileupload
!jupyter nbextension enable –py fileuploadimport wordcloud
import numpy as np
from matplotlib import pyplot as plt
from IPython.display import display
import fileupload
import io
import sys# This is the uploader widget
def _upload():_upload_widget = fileupload.FileUploadWidget()
def _cb(change):
global file_contents
decoded = io.StringIO(change[‘owner’].data.decode(‘utf-8’))
filename = change[‘owner’].filename
print(‘Uploaded{}
({:.2f} kB)’.format(
filename, len(decoded.read()) / 2 **10))
file_contents = decoded.getvalue()_upload_widget.observe(_cb, names=’data’)
display(_upload_widget)_upload()
#FileUploadWidget(label=’Browse’, _dom_classes=(‘widget_item’, ‘btn-group’))
# Here is a list of punctuations and uninteresting words you can use to process your text
punctuations = ”’!()-[]{};:'”\,<>./?@#$%^&*_~”’
uninteresting_words = [“the”, “a”, “to”, “if”, “is”, “it”, “of”, “and”, “or”, “an”, “as”, “i”, “me”, “my”, \
“we”, “our”, “ours”, “you”, “your”, “yours”, “he”, “she”, “him”, “his”, “her”, “hers”, “its”, “they”, “them”, \
“their”, “what”, “which”, “who”, “whom”, “this”, “that”, “am”, “are”, “was”, “were”, “be”, “been”, “being”, \
“have”, “has”, “had”, “do”, “does”, “did”, “but”, “at”, “by”, “with”, “from”, “here”, “when”, “where”, “how”, \
“all”, “any”, “both”, “each”, “few”, “more”, “some”, “such”, “no”, “nor”, “too”, “very”, “can”, “will”, “just”]# LEARNER CODE START HERE
newFile = “”
for index, char in enumerate(file_contents):
if (char.isalpha() == True or char.isspace()):
newFile += charnewFile = newFile.split()
wordCloudFile = []for word in newFile:
if ((word.lower() not in uninteresting_words) and (word.isalpha() == True)):
wordCloudFile.append(word)frequencies = {}
for word in wordCloudFile:
if (word.lower() not in frequencies):
frequencies[word.lower()] = 1
else:
frequencies[word.lower()] += 1#wordcloud
cloud = wordcloud.WordCloud()
cloud.generate_from_frequencies(frequencies)
return cloud.to_array()# Display your wordcloud image
myimage = calculate_frequencies(file_contents)
plt.imshow(myimage, interpolation = ‘nearest’)
plt.axis(‘off’)
plt.show()-
This topic was modified 2 years, 4 months ago by
Abhishek Tyagi.
-
This topic was modified 2 years, 4 months ago by
-
-
AuthorPosts
- You must be logged in to reply to this topic.