我想要团队名称和行的两列数据。但是我的所有输入都只是放在单元格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()"""
答案 0 :(得分:1)
这里你不应该这样做,因为你正在制作清单列表:
data = {'Team':[team], 'line' : [line]}
# ...
取而代之的是:
data = {'Team': team, 'line': line}
# ...