我正在尝试从 ESPN.com 上抓取一些评分并将它们放入 Pandas DataFrame 中。我过去以同样的方式做过类似的事情,没有任何问题。但是在这种情况下,当我尝试保存 DataFrame 时出现此错误。
RuntimeError:调用 Python 对象时超出最大递归深度
尝试将其保存为 hdf5 表时出现类似错误。
即使这个片段也给出了同样的错误。我很困惑为什么要这样做?它与功能有关吗?
url = 'http://espn.go.com/nba/boxscore?gameId=400278773'
boxurl = urllib2.urlopen(url).read()
soup = BeautifulSoup(boxurl)
tables = soup.findAll('table')
lineScoreTable = tables[-2]
lineScoreRows = lineScoreTable.findAll('tr')
def GetAwayQTRScores():
scoreRow = lineScoreRows[1].findAll('td')
awayQTRScores = []
for x in scoreRow:
scores = x.string
awayQTRScores.append(scores)
return awayQTRScores # returns list
awayQTRScores = GetAwayQTRScores()
awayTeam = awayQTRScores[0]
awayQ1 = int(awayQTRScores[1])
awayQ2 = int(awayQTRScores[2])
awayQ3 = int(awayQTRScores[3])
awayQ4 = int(awayQTRScores[4])
awayOT1 = np.nan if len(awayQTRScores) < 7 else int(awayQTRScores[5])
awayOT2 = np.nan if len(awayQTRScores) < 8 else int(awayQTRScores[6])
awayOT3 = np.nan if len(awayQTRScores) < 9 else int(awayQTRScores[7])
awayOT4 = np.nan if len(awayQTRScores) < 10 else int(awayQTRScores[8])
data = {'AwayTeam' :[awayTeam],
'AwayQ1' : [awayQ1],
'AwayQ2' : [awayQ2],
'AwayQ3' : [awayQ3],
'AwayQ4' : [awayQ4],
'AwayOT1' : [awayOT1],
'AwayOT2' : [awayOT2],
'AwayOT3' : [awayOT3],
'AwayOT4' : [awayOT4]}
testScrape = pd.DataFrame(data)
testScrape.save('testScrape')
() ----> 1 testScrape.save('testScrape') 中的 RuntimeError Traceback (最近一次调用最后一次)
C:\Python27\lib\site-packages\pandas\core\generic.pyc in save(self, path) 26 27 def save(self, path): ---> 28 com.save(self, path) 29 30 @classmethod
C:\Python27\lib\site-packages\pandas\core\common.pyc in save(obj, path) 1562 f = open(path, 'wb') 1563 try: -> 1564 pickle.dump(obj, f,协议=pickle.HIGHEST_PROTOCOL) 1565 最后:1566 f.close()
RuntimeError:调用 Python 对象时超出最大递归深度
print data
返回
{'AwayTeam':[u'LAL'],'AwayOT4':[nan],'AwayQ4':[27],'AwayQ3':[36],'AwayQ2':[24],'AwayQ1':[16 ],'AwayOT1':[nan],'AwayOT2':[nan],'AwayOT3':[nan]}