2016-07-27 4 views
1

2つのデータ列にチーム名と行が必要です。しかし、私のすべての入力はちょうどセルB1に配置されます。 (私のスニペットの一番下にコメントアウトされたコードがあることに注意してください)。すべてのチームをA列に、B列を下にするためにはループを使ってリストを繰り返し処理する必要があると思うが、パンダを使っている間に頭を包むことはできない。どんな助けでも大歓迎です!Python - パンダを使用したExcelスプレッドシートへのデータの書式設定

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

代わりに実行します:あなたはリストのリストを作っているので、あなたがこれを行うべきではありません

おかげでここ

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

あなたのコメントアウトコードが何を生産します私のテストで願っています。 – bernie

+0

私はすべての結果をセルB1に配置します。チームを1つの列に、行を別の列にします。それは理にかなっていますか? @bernie –

+0

私はちょうど私のテストでは、あなたが望むように出力されていると言っています。 – bernie

答えて

1

data = {'Team': team, 'line': line} 
# ... 
関連する問題