如何解决Panda 的数据框中仅打印了 118 行
我尝试使用 tweepy 和 panda 的数据框从特定日期抓取 Twitter 数据。但是只打印了固定的 118 行最近的数据。如何使用此代码抓取所有数据?另一个问题是我无法过滤两个特定日期之间的数据,例如:2019-01-01 到 2020-01-01。这个特定任务的代码是什么?请帮助我,我非常需要这个解决方案。这是我的代码:
import tweepy
import re
import pandas as pd
import itertools
import collections
import nltk
from nltk.corpus import stopwords
import matplotlib.pyplot as plt
from textblob import TextBlob
import os
import datetime
import sys
consumer_key = " "
consumer_secret = " "
access_token = " "
access_token_secret = " "
auth = tweepy.OAuthHandler(consumer_key,consumer_secret)
auth.set_access_token(access_token,access_token_secret)
api = tweepy.API(auth,wait_on_rate_limit=True,wait_on_rate_limit_notify=True)
date_since = "2019-01-01"
date_until = "2020-01-01"
tweets = tweepy.Cursor(api.search,q="Shopify (canada OR canadian)",since = date_since,#until = date_until,tweet_mode="extended",lang="en").items()
user_data = [[tweet.created_at,tweet.user.name,tweet.user.location,tweet.full_text,TextBlob(tweet.full_text).sentiment[0],'Positive' if TextBlob(tweet.full_text).sentiment[0] > 0
else 'Negative' if TextBlob(tweet.full_text).sentiment[0] < 0
else 'Nuetral'] for tweet in tweets]
df = pd.DataFrame(data=user_data,columns=['Created At',"User",'Location','Text','Sentiment','Polarity'])
df.to_excel("output.xlsx")
df.head(1000)
解决方法
根据 twitter documentation,您的搜索 API 只能获取从到日期的前 1 周数据。此外,因为 参数已被弃用。您可以在 twitter 的文档页面上找到所有参数。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。