Last active
November 5, 2021 02:54
-
-
Save rsalaza4/f995abfe63b32a39f240aaeb704d8610 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # Import required libraries | |
| from wordcloud import WordCloud | |
| import matplotlib.pyplot as plt | |
| plt.style.use('seaborn-whitegrid') | |
| import matplotlib as mpl | |
| # Set wordcloud size | |
| mpl.rcParams['figure.figsize'] = [20.0, 10.0] | |
| # Define a wordcloud function | |
| def wordcloud(text, title=""): | |
| # Create word cloud | |
| df_cloud = WordCloud(width=500, colormap='RdYlBu').generate(text) | |
| # Display word cloud | |
| plt.imshow(df_cloud) | |
| # Remove axis | |
| plt.axis("off") | |
| # Update fint dictionary | |
| fontdict = {"fontsize": 36, "fontweight" : "bold"} | |
| # Set wordcloud title | |
| plt.title(title, fontdict=fontdict) | |
| # Show word cloud | |
| plt.show() | |
| # Generate word clouds for each Medium publication on the data frame | |
| for publication in df["publication"].unique(): | |
| wordcloud(df[df["publication"]==publication].clean_title.str.cat(sep=" "), title= f"{publication} Word Cloud") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment