码迷,mamicode.com
首页 > 编程语言 > 详细

Python 可视化Twitter中指定话题中Tweet的词汇频率

时间:2014-07-08 10:45:15      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:twitter   数据挖掘   可视化   

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

bubuko.com,布布扣

Python 可视化Twitter中指定话题中Tweet的词汇频率,布布扣,bubuko.com

Python 可视化Twitter中指定话题中Tweet的词汇频率

标签:twitter   数据挖掘   可视化   

原文地址:http://blog.csdn.net/guaguastd/article/details/37554913

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!