Skip to content

Instantly share code, notes, and snippets.

@fclesio
Created July 3, 2019 10:42
Show Gist options
  • Save fclesio/207ebed0157421053818067632375676 to your computer and use it in GitHub Desktop.
Save fclesio/207ebed0157421053818067632375676 to your computer and use it in GitHub Desktop.
# Word cloud with most common words
def show_wordcloud(text, artist):
# Create and generate a word cloud image:
wordcloud = WordCloud(stopwords=stoplist, background_color="white").generate(text)
# Display the generated image:
fig = plt.figure(figsize=(25,10))
plt.imshow(wordcloud, interpolation='bilinear')
plt.title(f'Word Cloud for {artist}', fontsize=20)
plt.axis("off")
plt.show()
fig.savefig(f'word_cloud_{artist}.png', format='png', dpi=500)
def get_wordcloud(df, artist):
dataframe = df[df['artist'] == artist]
# Get all texts and generate a cloud
text = " ".join(review for review in dataframe.lyric)
show_wordcloud(text, artist)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment