user6646201
user6646201

Reputation:

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!

Thanks

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()"""

Upvotes: 1

Views: 139

Answers (1)

mechanical_meat
mechanical_meat

Reputation: 169304

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}
# ...

Upvotes: 1

Related Questions