Python 可视化Twitter中指定话题中Tweet的词汇频率
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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的词汇频率的主要内容,如果未能解决你的问题,请参考以下文章
如何在python的多线程环境中指定一部分代码在特定线程中运行?
R语言ggplot2可视化:ggplot2可视化使用labs函数为可视化图像添加(caption)图片说明文字theme_bw中指定参数base_size来改变图片说明文字轴标签等的大小
在 pypi python setup.py 中指定可选依赖项
R语言ggplot2可视化:ggplot2可视化基本散点图(scatter plot)通过在theme_bw中指定参数base_size来改变轴标签的大小并控制网格线和轴标签的大小