Created
August 30, 2017 13:22
-
-
Save dzamlo/ec5ab24bcce52d02fc455993a91cfb0d 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 fileinput | |
import tokenize | |
import matplotlib.pyplot as plt | |
from wordcloud import WordCloud | |
if __name__ == '__main__': | |
# If some files don't have the same encoding, this is likely to not work correctly. | |
tokens = tokenize.tokenize(fileinput.input(mode='rb').readline) | |
tokens_no_string = (t for t in tokens if t.type not in [tokenize.ENCODING, tokenize.STRING]) | |
tokens_lowercase_str = (t.string.lower() for t in tokens_no_string) | |
wordcloud = WordCloud().generate("\n".join(tokens_lowercase_str)) | |
plt.imsave("/tmp/foo.png", wordcloud) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment