0
我用熊貓在桌子上,在這個環節預期:熊貓據幀未正常工作
http://sports.yahoo.com/nfl/stats/byposition?pos=QB&conference=NFL&year=season_2014&sort=49&timeframe=All
我試圖創建的球員對象從每個(相關的)行。所以,我想通過結束第3行,我用了一堆不同的領域,構建一個玩家對象,包括姓名,團隊,傳球碼等
這裏是我的嘗試:
def getAllQBs():
QBs = []
table = pd.read_html(requests.get(QB_LINK).content)[5]
finalTable = table[2 : ]
print(finalTable)
for row in finalTable.iterrows():
print(row)
name = row[0]
team = row[1]
passingYards = row[7]
passingTouchdowns = row[10]
interceptions = row[11]
rushingYards = row[13]
rushingTouchdowns = row[16]
rushingFumbles = row[19]
newQB = QB(name, team, rushingYards, rushingTouchdowns, rushingFumbles, passingYards, passingTouchdowns, interceptions)
QBs.append(newQB)
print(newQB.toString())
return QBs
傳遞碼是行左邊的第8個元素,所以我想我可以使用row[7]
來訪問它。然而,當我運行這個功能時,我得到:
Traceback (most recent call last):
File "main.py", line 66, in <module>
main()
File "main.py", line 64, in main
getAllQBs()
File "main.py", line 27, in getAllQBs
passingYards = row[7]
IndexError: tuple index out of range
看起來好像我無意中使用了列。然而,我用DataFrame.iterrows()
,我認爲會照顧這...
任何想法?
感謝, bclayman