Skip to content

Instantly share code, notes, and snippets.

@ravi07bec
Last active October 29, 2020 06:33
Show Gist options
  • Save ravi07bec/fa5c123fa15d8f2a782495941fe2bb9f to your computer and use it in GitHub Desktop.
Save ravi07bec/fa5c123fa15d8f2a782495941fe2bb9f to your computer and use it in GitHub Desktop.
stopwords = set(STOPWORDS)
import random
foo = ['black','white']
for i in variety:
subset=data[data['variety']==i]
subset['description']=subset['description'].str.lower()
subset['description2']=subset['description'].apply(lambda x: ' '.join([word for word in x.split() if word not in (stopwords)]))
text = " ".join(review for review in subset.description2)
wc = WordCloud(background_color=random.choice(foo), max_words=100, mask=transformed_wine_mask,
stopwords=stopwords, contour_width=3,min_word_length=4, contour_color='firebrick')
# Generate a wordcloud
wc.generate(text)
st1="image/wine_"+i+"_.png"
st2="wine_"+i+"_.png"
# store to file
wc.to_file(st1)
wc.to_file(st2)
-------Calling Image wordcloud in Dash App
def update_body_image(slider):
str1="wine_"+"All"+"_.png"
if(slider):
str1="wine_"+slider+"_.png"
image_filename = str1 # replace with your own image
print(image_filename)
encoded_image = base64.b64encode(open(image_filename, 'rb').read())
src = 'data:image/png;base64,{}'.format(encoded_image.decode())
return src
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment