Skip to content

Instantly share code, notes, and snippets.

@agusmakmun
Created June 1, 2016 21:41
Show Gist options
  • Save agusmakmun/640bfeea24928c1e68f74af7ef7892c8 to your computer and use it in GitHub Desktop.
Save agusmakmun/640bfeea24928c1e68f74af7ef7892c8 to your computer and use it in GitHub Desktop.
medium_twitter_mining_7
from collections import Counter
# get top ten entities
top_words = [item[0] for item in Counter(words).most_common()[:10]]
top_words_freq = [item[1] for item in Counter(words).most_common()[:10]]
top_screen_names = [item[0] for item in Counter(screen_names).most_common()[:10]]
top_screen_names_freq = [item[1] for item in Counter(screen_names).most_common()[:10]]
top_hashtags = [item[0] for item in Counter(hashtags).most_common()[:10]]
top_hashtags_freq = [item[1] for item in Counter(hashtags).most_common()[:10]]
# print the results as a table
pt = PrettyTable()
pt.add_column('Words',top_words)
pt.add_column('Frequency',top_words_freq)
pt.add_column('Screen Names',top_screen_names)
pt.add_column('Frequency',top_screen_names_freq)
pt.add_column('Hashtags',top_hashtags)
pt.add_column('Frequency',top_hashtags_freq)
print pt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment