我正在尝试用户对subreddit进行分析。当我尝试将数据(df)发送到excel时,我收到此错误:AttributeError: 'list' object has no attribute 'to_excel
。我的代码如下。
import config
import pandas as pd
import os
import itertools
import xlsxwriter
df = []
def bot_login():
print ("logging in")
r = praw.Reddit(username = config.username,
password = config.password,
client_id = config.client_id,
client_secret = config.client_secret,
user_agent= "u/1234 testing bot for lerns programming")
print("logged in")
return r
def run_bot(r):
settings = {'subreddit': 'test'}
submissions = r.subreddit(settings['subreddit']).new(limit=1)
print('still working')
for s in submissions:
print("Downvoted: '{}'".format(s.title[0:70]))
df.append(s.author)
time.sleep(2)
r = bot_login()
run_bot(r)
os.chdir('C:/users/jonathan/desktop/data')
df.to_excel('Users.xlsx')
print(df)