我想要两列数据:团队名称和线路。然而我的所有输入都只是放入单元格 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}
# ...
我是一名优秀的程序员,十分优秀!