C2H50H C2H50H - 2 months ago 15x
Python Question

Python - Formatting Data into Excel Spreadsheet Using pandas

I want two columns of data the team name and the line. However all my input is just placed into cell B1. (Note that was with the commented out code at the bottom of my snippet). I think I need to iterate through my lists with for loops to get all the teams down the A column, and lines down the B column, but just can't wrap my head around it while doing it with pandas. Any help would be greatly appreciated!


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"]):

for tr in table.find_all("tr", class_="team"):

for td in tr.find_all("td", ["currentline"]):
# 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')



Here you should not do this because you're making lists of lists:

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

Instead do:

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