Python – 将数据格式化为Excel电子表格使用pandas

我想要两列数据的团队名称和行。 然而,我所有的input只是放在单元格B1中。 (请注意,在我的代码片段底部注释掉了代码)。 我想我需要循环遍历我的列表for循环,让所有的团队沿着A列,沿着B列向下,但只是用pandas来包裹我的头。 任何帮助将不胜感激!

谢谢

team = [] line = [] # Each row in table find all rows with class name team for tr in table.find_all("tr", class_="team"): # Place all text with identifier 'name' in list named team for td in tr.find_all("td", ["name"]): team.append(td.text.strip()) for tr in table.find_all("tr", class_="team"): for td in tr.find_all("td", ["currentline"]): line.append(td.text.strip()) # Amount of data in lists x = len(team) # Team name is list team, Line in list line. Create relationship between both data sets # Creating Excel Document and Placing Team Name in column A, Placing Line in Column B #Need to add data into Excel somehow for i in range(0,1): for j to line: """ data = {'Team':[team], 'line' : [line]} table = pd.DataFrame(data) writer = pd.ExcelWriter('Scrape.xlsx') table.to_excel(writer, 'Scrape 1') writer.save()""" 

在这里,你不应该这样做,因为你正在列出清单:

 data = {'Team':[team], 'line' : [line]} # ... 

相反:

 data = {'Team': team, 'line': line} # ...