【发布时间】:2016-07-27 22:03:22
【问题描述】:
我想要两列数据,团队名称和行。然而,我所有的输入都只是放在单元格 B1 中。 (请注意,这是在我的 sn-p 底部注释掉的代码)。我认为我需要使用 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()"""
【问题讨论】:
-
您注释掉的代码会在我的测试中产生您希望的结果。
-
它将我所有的结果放入单元格 B1 我希望团队在一列中,而行在另一列中。那有意义吗? @伯尼
-
有道理我只是说在我的测试中输出如你所愿。
-
嗯,这真的很奇怪,知道为什么会这样,你有哪一年的优秀成绩? @伯尼
-
我现在是 2013 年。不知道你的情况出了什么问题......
标签: python excel pandas beautifulsoup