首页 > 代码库 > Python 可视化Twitter中指定话题中Tweet的词汇频率
Python 可视化Twitter中指定话题中Tweet的词汇频率
CODE:
#!/usr/bin/python # -*- coding: utf-8 -*- ‘‘‘ Created on 2014-7-8 @author: guaguastd @name: plot_frequencies_words.py ‘‘‘ if __name__ == ‘__main__‘: #import json # import Counter from collections import Counter # import search from search import search_for_tweet # import visualize from visualize import visualize_for_frequencies # import login, see http://blog.csdn.net/guaguastd/article/details/31706155 from login import twitter_login # get the twitter access api twitter_api = twitter_login() # import tweet from tweet import extract_tweet_entities while 1: query = raw_input(‘\nInput the query (eg. #MentionSomeoneImportantForYou, exit to quit): ‘) if query == ‘exit‘: print ‘Successfully exit!‘ break statuses = search_for_tweet(twitter_api, query) status_texts,screen_names,hashtags,words = extract_tweet_entities(statuses) word_counts = sorted(Counter(words).values(), reverse=True) visualize_for_frequencies(word_counts, "Word Rank", "Freq")
RESULT:
Input the query (eg. #MentionSomeoneImportantForYou, exit to quit): #MentionSomeoneImportantForYou Length of statuses 100 Length of statuses 196
Python 可视化Twitter中指定话题中Tweet的词汇频率
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。