Python 使用R设置推文格式,就像推文归档一样
我想知道如何像Twitter归档一样格式化CSV文件,这样R在读取CSV文件时就不会有问题(遇到了很多问题,没有解决方案)。Twitter档案是一个用户时间轴,我的CSV(我将使用R对其进行情绪分析)是一个包含tweet的搜索结果 Twitter存档的示例Python 使用R设置推文格式,就像推文归档一样,python,r,csv,tweepy,Python,R,Csv,Tweepy,我想知道如何像Twitter归档一样格式化CSV文件,这样R在读取CSV文件时就不会有问题(遇到了很多问题,没有解决方案)。Twitter档案是一个用户时间轴,我的CSV(我将使用R对其进行情绪分析)是一个包含tweet的搜索结果 Twitter存档的示例 "tweet_id","in_reply_to_status_id","in_reply_to_user_id","timestamp","source","text","retweeted_status_id","retweeted_sta
"tweet_id","in_reply_to_status_id","in_reply_to_user_id","timestamp","source","text","retweeted_status_id","retweeted_status_user_id","retweeted_status_timestamp","expanded_urls"
"81423594213695488","","","2016-12-29 14:18:08 +0000","<a href=""http://twitter.com/download/android"" rel=""nofollow"">Twitter for Android</a>","RT @SwiftOnSecurity: We're going to tell kids that laptops used to store data on tiny mirrors spinning @ 7200rpm and they're going to think…","814187405175570432","2436389418","2016-12-28 19:12:58 +0000",""
"876926582348550143","","","2016-12-22 13:29:16 +0000","<a href=""http://twitter.com/download/android"" rel=""nofollow"">Twitter for Android</a>","RT @MKBHD: Shout-out to everyone going home and becoming family tech support for the holidays","811910809521680384","29873662","2016-12-22 12:26:36 +0000",""
我如何在Python中实现它:
csvFile = open('tweets.csv', 'a')
csvWriter = csv.writer(csvFile, delimiter=',')
for tweet in tweepy.Cursor(api.search,
q="trump",
rpp=100,
result_type="recent",
include_entities=True,
lang="en").items(5):
print (tweet.text)
csvWriter.writerow([tweet.text.encode('utf-8')])
csvFile.close()
我对R中的解决方案持开放态度,我不完全理解您的问题,但您可能想看看R中的twitteR库,尤其是函数“twlisttof”。如果你把它与write.csv结合起来,你就可以纠正你收集的tweets的csv格式,而R也可以阅读
write.csv(twListToDF(your_tweets), file="your_tweets.csv")
R中有一个软件包可以让你下载推文,它叫twitteR。您还可以根据日期和语言从那里下载推文,然后将其写成csv。
write.csv(twListToDF(your_tweets), file="your_tweets.csv")