Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将推文导出到数据帧_Python_Twitter - Fatal编程技术网

Python 将推文导出到数据帧

Python 将推文导出到数据帧,python,twitter,Python,Twitter,我无法将用户信息导出为数据帧,即使打印(用户信息)时在控制台中显示良好。有人能帮忙吗?谢谢 # Define the search term and the date_since date as variables search_words = "#sunrise" date_since = "2019-09-01" # Collect tweets tweets = tw.Cursor(api.search, q=search_words,

我无法将用户信息导出为数据帧,即使打印(用户信息)时在控制台中显示良好。有人能帮忙吗?谢谢

# Define the search term and the date_since date as variables
search_words = "#sunrise"
date_since = "2019-09-01"

# Collect tweets
tweets = tw.Cursor(api.search,
              q=search_words,
              lang="en",
              since=date_since).items(5)

users_info = [[tweet.user.screen_name, tweet.user.location, tweet.text, tweet.created_at, tweet.retweet_count, tweet.source] for tweet in tweets]

df = pd.DataFrame(users_info, columns =['user_name','user_location', 'text', 'date', 'retweet_count', 'url'])
df.to_excel=('sunrise_tweets.xlsx')

df.to\u excel
之后不应该有
=
,因为这会导致文件名被分配到
df.to\u excel
而不是调用
df.to\u excel
方法:

df.to_excel('sunrise_tweets.xlsx')
还要确保您已经安装或安装了。有关更多信息,请参阅