我正在尝试使用python中的pandas附加excel表的行。 问题是代码在运行,最后我只看到在工作表中添加了1行,而不是调用循环以插入数据的行数。
以下是我读取数据帧的初始化代码
def __init__(self,readLink):
self.fileName = 'data.xlsx'
if readLink==0:
self.linksToRead = 10000
else:
self.linksToRead = readLink
self.linkCount = 0
self.wordsList =[]
self.df = pd.read_excel(self.fileName, sheetname='Sheet1')
if len(self.df) > 0:
self.parsedLinks = self.df['link'].tolist()
else:
self.parsedLinks=[]
self.urlList =[]
self.writer = pd.ExcelWriter(self.fileName)
self.Start('https://www.bbc.com/urdu/pakistan-44652896')
遵循在循环内运行的代码,并打算使用数据框在表格中附加excel行。
df2 = pd.DataFrame(data = [[URL, ",".join(allKeywords), ",".join(keyphrasesExisted),articleText,"ASDF"]],
columns=['link', 'AllKeywords','PresentKeywords', 'Article','a'])
self.df = pd.concat([self.df,df2])
self.df.to_excel(self.writer,index=False,sheet_name="Sheet1",header=True)
self.writer.save()
print("Added")