Managing My Impression

Dr. Timothy D. Bowman, Assistant Professor, Wayne State University

Top 200 @Mentions and #Hashtags used in tweets from 2017 dump as Word Cloud using Python

A follow up to the Twitter profile description word cloud… I’ve created a hashtag word cloud from the 19.2 million hashtags used in the tweets collected by

Top 200 Hashtags used in tweets collected by
Top 200 @Mentions used in tweets collected by

The Python code is VERY similar to the profile description word cloud code, however we have to turn off the ‘collocations’ option in the WordCloud module options to make it work as we expect.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
Created on Sun Feb 10 16:19:56 2019

@author: tdbowman
import io
import csv
import numpy as np
from wordcloud import WordCloud, STOPWORDS
from os import path
from PIL import Image

# current directory
currdir = path.dirname(__file__)

# from
def create_wordcloud(text):

    # use cloud.png as mask for word cloud
    mask = np.array(, "cloud.png")))
    # create set of stopwords	
    #stop_words = list(STOPWORDS)
    # create wordcloud object
    wc = WordCloud(collocations=False,
    # generate wordcloud
    # save wordcloud
    wc.to_file(path.join(currdir, "wc_hashtags.png"))
if __name__ == "__main__":

    # Grab text from file and convert to list
    your_list = []
    with'hashtags.csv', 'r', encoding='utf-8') as f:
        reader = csv.reader(x.replace('\0', '') for x in f)
        your_list = ','.join([i[0] for i in reader])    
    # generate wordcloud

Leave a Reply

Your email address will not be published. Required fields are marked *