python - sportsreference API 错误数据问题
问题描述
我正在使用sportsreference API 来获取一些数据,但我不确定我做错了什么或者API 有问题。当我使用 API 提取我需要的数据时,它总是说客队赢了,即使在比赛中也不是这样。
代码片段:
from sportsreference.nba.boxscore import Boxscores
from sportsreference.nba.boxscore import Boxscore
# Select range of dates to get boxscores from (year, month, day)
games = Boxscores(datetime(2017, 10, 17), datetime(2017, 10, 20))
# Get boxscore abbreviations to get more detailed game boxscores
boxscore_abvs = []
for key in games.games.keys():
for i in range(len(games.games[key])):
boxscore_abvs.append(games.games[key][i]['boxscore'])
# Get more detailed boxscores
df = pd.DataFrame()
for abv in boxscore_abvs:
game_data = Boxscore(abv)
temp_df = game_data.dataframe
df = df.append(temp_df)
df 的错误输出示例(骑士队赢得了这场比赛,API 报告凯尔特人队):
away_assist_percentage away_assists away_block_percentage away_blocks away_defensive_rating ... losing_name pace winner winning_abbr winning_name
201710170CLE 66.7 24 6.6 4 102.7 ... Cleveland Cavaliers 99.3 Away BOS Boston Celtics
解决方案
这是一个由站点更改其 HTML 布局引起的已知问题。似乎它应该在0.6.0
版本中修复:https ://github.com/roclark/sportsreference/pull/506 。
同时,您可以从 git 安装以获取固定版本:
pip install --force-reinstall git+https://github.com/roclark/sportsreference.git@master
这样,我得到了正确的结果:
Boxscore('201710170CLE').dataframe[['away_points', 'home_points', 'winning_name']]
# away_points home_points winning_name
# 201710170CLE 99 102 Cleveland Cavaliers
推荐阅读
- reactjs - React table 复选框使用已删除行的状态
- excel - 打开文件后子程序停止工作
- java - 替代响应spring boot api rest
- asp.net-core - dotnet publish -o published 每次发布都会创建嵌套目录
- google-cloud-platform - 是否有任何 Google API 可以获取 url 路径中没有项目的区域列表?
- amazon-web-services - 如果我将 Google App Engine 服务移至 Amazon Lambda 函数,s3 文件大小下载限制有多高?
- javascript - 是否可以用不使用后视的东西替换正则表达式中的否定“环顾四周”?
- python - 如何在python中找到函数对象的所需参数?
- c# - 检查两个字段组合的唯一性
- reactjs - 如何将字符串转换为纯 html?