一个python包,用于刮除nba api并返回逐局播放文件
nba-scraper的Python项目详细描述
nba_scraper
这是一个用python编写的包,用于刮除nba的api并生成
在csv
文件或pandas
数据帧中按次玩游戏。这个包裹
有两个主要功能scrape_game
,它可以抓取单个游戏或列表
特别的比赛,以及scrape_season
这使得整个赛季的常规赛
赛季赛。
到目前为止,这项计划只在2016赛季才开始实施。计划 是为了能够刮去旧的季节,然而这些旧的季节 不会像最近几季那样有所有活动的X/Y位置。
安装
要安装此软件包,只需在命令行中键入此命令:
pip install nba_scraper
用法
scrape_game
默认数据格式是pandas数据框,您可以将其更改为csv
使用data_format
参数。默认文件路径是
用户主目录您可以使用data_dir
参数更改此目录
import nba_scraper.nba_scraper as ns
# if you want to return a dataframe
# you can pass the function a list of strings or integers
# all nba game ids have two leading zeros but you can omit these
# to make it easier to create lists of game ids as I add them on
nba_df = ns.scrape_game([21800001, 21800002])
# if you want a csv if you don't pass a file path the default is home
# directory
ns.scrape_game([21800001, 21800002], data_format='csv', data_dir='file/path')
scrape_season
使用data_format
和data_dir
关键字的方式与
scrape_game
。不过,你可以通过你想要的赛季,而不是游戏ID
刮到功能。这个季节是一个四位数的年份,必须是
整数。
import nba_scraper.nba_scraper as ns
#scrape a season
nba_df = ns.scrape_season(2019)
# if you want a csv if you don't pass a file path the default is home
# directory
ns.scrape_season(2019, data_format='csv', data_dir='file/path')
scrape_date_range
这允许您删除所有的常规赛日期范围内的游戏
功能。从现在起,它不会刮季后赛的比赛。日期格式必须
以YYYY-MM-DD
格式传递。
import nba_scraper.nba_scraper as ns
#scrape a season
nba_df = ns.scrape_date_range('2019-01-01', 2019-01-03')
# if you want a csv if you don't pass a file path the default is home
# directory
ns.scrape_date_range('2019-01-01', 2019-01-03', data_format='csv', data_dir='file/path')
联系人
如果您有任何问题或错误,请打开问题/错误报告。如果你有 任何改进/建议请提交请求。如果它掉到外面 这两个区域请随时给我发电子邮件 matt@barloweanalytics.com。