Last active
October 29, 2020 06:33
-
-
Save ravi07bec/fa5c123fa15d8f2a782495941fe2bb9f 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
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