nba-history

aquire historical nba data about players and teams


Keywords
nba, basketball, scraping, data, mining, reference, bs4
License
MIT
Install
pip install nba-history==1.1.5

Documentation

Alt text

Version Downloads Coverage

nba_history is a python package for dynamically scraping NBA player, team, and draft data.

All nba_history functions return scraped data as a pandas dataframe with an option to also export to CSV.

Example

from nba_history import player_data, team_data

# scrape 2013 NBA draft picks
df = player_data.scrape_draft_data(start_year = 2013,
	end_year = 2013,
	export = False)
	
print(df.head())

Alt text

Installation

nba_history depends on the Python modules requests, beautifulsoup, and pandas

Installation with pip: if you have pip installed, type this in a terminal:

$ python -m pip install nba_history

Installation by hand: download the sources, either from PyPI or, if you want the development version, from GitHub, unzip everything into one folder, open a terminal and type:

$ (sudo) python setup.cfg install

Documentation

The nba_history package has 2 modules, player_data and team_data

List of all functions in player_data module

scrape_draft_data

Scrape NBA draft data by year, including:

  • draft round
  • draft pick number
  • college
  • years in the NBA
  • and much more..

function arguments

  • start_year: first year to scrape
  • end_year: last year to scrape
  • export: option to export to CSV. Default is set as True
from nba_history import player_data

# scrape 2017-2020 NBA draft picks
df = player_data.scrape_draft_data(start_year = 2017,
	end_year = 2020,
	export = True)

scrape_player_salaries

Scrape NBA player salary by year, including:

  • League Rank
  • Player
  • Salary

function arguments

  • start_year: first year to scrape
  • end_year: last year to scrape
  • export: option to export to CSV. Default is set as True
  • sleep_time: time to pause function between sraping each year. Default is set as 2 seconds, if scraping >10 years then changing to 1 second is recommended.
from nba_history import player_data

# scrape 2001-2003 player salaries
df = player_data.scrape_player_salaries(start_year = 2001,
	end_year = 2003,
	export = True,
	sleep_time = 2)

scrape_player_total_stats

Scrape NBA player total stats by year, including:

  • Points
  • Rebounds
  • Assists
  • Minutes
  • Games
  • 3PA
  • and much more..

function arguments: function arguments

  • start_year: first year to scrape
  • end_year: last year to scrape
  • export: option to export to CSV. Default is set as True
  • sleep_time: time to pause function between sraping each year. Default is set as 2 seconds, if scraping >10 years then changing to 1 second is recommended.
from nba_history import player_data

# scrape 2011-2015 player total stats
df = player_data.scrape_player_total_stats(start_year = 2011,
	end_year = 2015,
	export = True,
	sleep_time = 2)

scrape_player_per_game_stats

Scrape NBA player per game stats by year, including:

  • Points
  • Rebounds
  • FG%
  • Minutes
  • 3P%
  • and much more..

function arguments

  • start_year: first year to scrape
  • end_year: last year to scrape
  • export: option to export to CSV. Default is set as True
  • sleep_time: time to pause function between sraping each year. Default is set as 2 seconds, if scraping >10 years then changing to 1 second is recommended.
from nba_history import player_data

# scrape 2000-2009 player per game stats
df = player_data.scrape_player_per_game_stats(start_year = 2000,
	end_year = 2009,
	export = True,
	sleep_time = 2)

scrape_player_advanced_stats

Scrape NBA player advanced stats by year, including:

  • PER
  • WS
  • ORB%
  • 3PAr
  • and much more..

function arguments

  • start_year: first year to scrape
  • end_year: last year to scrape
  • export: option to export to CSV. Default is set as True
  • sleep_time: time to pause function between sraping each year. Default is set as 2 seconds, if scraping >10 years then changing to 1 second is recommended.
from nba_history import player_data

# scrape 1998-2001 advanced stats
df = player_data.scrape_player_advanced_stats(start_year = 1998,
	end_year = 2001,
	export = True,
	sleep_time = 2)

scrape_player_shooting_stats

Scrape NBA player shooting stats by year, including:

  • Dunks
  • FG% by distance
  • % of FG by distance
  • Corner 3PT%
  • and much more..

function arguments

  • start_year: first year to scrape
  • end_year: last year to scrape
  • export: option to export to CSV. Default is set as True
  • sleep_time: time to pause function between sraping each year. Default is set as 2 seconds, if scraping >10 years then changing to 1 second is recommended.
from nba_history import player_data

# scrape 1980-1985 player shooting stats
df = player_data.scrape_player_shooting_stats(start_year = 1980,
	end_year = 1985,
	export = True,
	sleep_time = 2)

scrape_all_stars

Scrape all NBA All-Stars for alltime, including:

  • Hall of Fame status
  • All Star appearances
  • and more..

function arguments:

  • export: option to export to CSV. Default is set as True
from nba_history import player_data

# scrape all NBA All-Stars alltime
df = player_data.scrape_all_stars(export = True)

List of all functions in team_data module

scrape_nba_team_records

Scrape NBA team records by year, including:

  • Playoff appearance
  • Wins
  • Losses
  • PPG
  • and much more..

function arguments

  • start_year: first year to scrape
  • end_year: last year to scrape
  • export: option to export to CSV. Default is set as True
from nba_history import team_data

# scrape 2010-2018 player per game stats
df = team_data.scrape_nba_team_records(start_year = 2010,
	end_year = 2018,
	export = True)

Contribute

nba_history is open-source library originally written by odonnell31 and released under the MIT licence. The project is hosted on GitHub, where everyone is welcome to contribute, ask for help or simply give feedback.

Maintainers