NCAAB Package

The NCAAB package offers multiple modules which can be used to retrieve information and statistics for Men’s Division I College Basketball, such as team names, season stats, game schedules, and boxscore metrics.

Boxscore

The Boxscore module can be used to grab information from a specific game. Metrics range from number of points scored to the number of blocked shots, to the assist percentage and much more. The Boxscore can be easily queried by passing a boxscore’s URI on sports-reference.com which can be retrieved from the Schedule class (see Schedule module below for more information on retrieving game-specific information).

from sportsreference.ncaab.boxscore import Boxscore

game_data = Boxscore('2018-04-02-21-villanova')
print(game_data.home_points)  # Prints 79
print(game_data.away_points)  # Prints 62
df = game_data.dataframe  # Returns a Pandas DataFrame of game metrics

The Boxscore module also contains a Boxscores class which searches for all games played on a particular day and returns a dictionary of matchups between all teams on the requested day. The dictionary includes the names and abbreviations for each matchup as well as the boxscore link if applicable.

from datetime import datetime
from sportsreference.ncaab.boxscore import Boxscores

games_today = Boxscores(datetime.today())
print(games_today.games)  # Prints a dictionary of all matchups for today

The Boxscores class also allows the ability to query over a range of dates using a second optional parameter during instantiation of the class. To query a range of dates, enter the start date as the first parameter and the inclusive end date as the second parameter.

from datetime import datetime
from sportsreference.ncaab.boxscore import Boxscores

# Pulls all games between and including November 11, 2017 and November 12,
# 2017
games = Boxscores(datetime(2017, 11, 11), datetime(2017, 11, 12))
# Prints a dictionary of all results from November 11, 2017 and November 12,
# 2017
print(games.games)
class sportsreference.ncaab.boxscore.Boxscore(uri)[source]

Bases: object

Detailed information about the final statistics for a game.

Stores all relevant metrics for a game such as the date, time, location, result, and more advanced metrics such as the effective field goal rate, the true shooting percentage, the game’s pace, and much more.

Parameters:uri (string) – The relative link to the boxscore HTML page, such as ‘2017-11-10-21-kansas’.
away_assist_percentage

Returns a float of the percentage of the away team’s field goals that were assisted. Percentage ranges from 0-100.

away_assists

Returns an int of the total number of assists by the away team.

away_block_percentage

Returns a float of the percentage of 2-point field goals that were blocked by the away team. Percentage ranges from 0-100.

away_blocks

Returns an int of the total number of blocks by the away team.

away_defensive_rating

Returns a float of the average number of points scored per 100 possessions by the away team.

away_defensive_rebound_percentage

Returns a float of the percentage of available defensive rebounds the away team grabbed. Percentage ranges from 0-100.

away_defensive_rebounds

Returns an int of the total number of defensive rebounds by the away team.

away_effective_field_goal_percentage

Returns a float of the away team’s field goal percentage while giving extra weight to 3-point field goals. Percentage ranges from 0-1.

away_field_goal_attempts

Returns an int of the total number of field goal attempts by the away team.

away_field_goal_percentage

Returns a float of the number of field goals made divided by the total number of field goal attempts by the away team. Percentage ranges from 0-1.

away_field_goals

Returns an int of the total number of field goals made by the away team.

away_free_throw_attempt_rate

Returns a float of the average number of free throw attempts per field goal attempt by the away team.

away_free_throw_attempts

Returns an int of the total number of free throw attempts by the away team.

away_free_throw_percentage

Returns a float of the number of free throws made divided by the number of free throw attempts by the away team.

away_free_throws

Returns an int of the total number of free throws made by the away team.

away_losses

Returns an int of the number of games the team has lost after the conclusion of the game.

away_minutes_played

Returns an int of the total number of minutes the team played during the game.

away_offensive_rating

Returns a float of the average number of points scored per 100 possessions by the away team.

away_offensive_rebound_percentage

Returns a float of the percentage of available offensive rebounds the away team grabbed. Percentage ranges from 0-100.

away_offensive_rebounds

Returns an int of the total number of offensive rebounds by the away team.

away_personal_fouls

Returns an int of the total number of personal fouls by the away team.

away_players

Returns a list of BoxscorePlayer class instances for each player on the away team.

away_points

Returns an int of the number of points the away team scored.

away_ranking

Returns an int of the away team’s ranking during the week, or None if the team wasn’t ranked.

away_steal_percentage

Returns a float of the percentage of possessions that ended in a steal by the away team. Percentage ranges from 0-100.

away_steals

Returns an int of the total number of steals by the away team.

away_three_point_attempt_rate

Returns a float of the percentage of field goal attempts from 3-point range by the away team. Percentage ranges from 0-1.

away_three_point_field_goal_attempts

Returns an int of the total number of three point field goal attempts by the away team.

away_three_point_field_goal_percentage

Returns a float of the number of three point field goals made divided by the number of three point field goal attempts by the away team. Percentage ranges from 0-1.

away_three_point_field_goals

Returns an int of the total number of three point field goals made by the away team.

away_total_rebound_percentage

Returns a float of the percentage of available rebounds the away team grabbed. Percentage ranges from 0-100.

away_total_rebounds

Returns an int of the total number of rebounds by the away team.

away_true_shooting_percentage

Returns a float of the away team’s true shooting percentage which considers free throws, 2-point field goals, and 3-point field goals. Percentage ranges from 0-1.

away_turnover_percentage

Returns a float of the number of times the away team turned the ball over per 100 possessions.

away_turnovers

Returns an int of the total number of turnovers by the away team.

away_two_point_field_goal_attempts

Returns an int of the total number of two point field goal attempts by the away team.

away_two_point_field_goal_percentage

Returns a float of the number of two point field goals made divided by the number of two point field goal attempts by the away team. Percentage ranges from 0-1.

away_two_point_field_goals

Returns an int of the total number of two point field goals made by the away team.

away_win_percentage

Returns a float of the percentage of games the away team has won after the conclusion of the game. Percentage ranges from 0-1.

away_wins

Returns an int of the number of games the team has won after the conclusion of the game.

dataframe

Returns a pandas DataFrame containing all other class properties and values. The index for the DataFrame is the string URI that is used to instantiate the class, such as ‘2017-11-10-21-kansas’.

date

Returns a string of the date the game took place.

home_assist_percentage

Returns a float of the percentage of the home team’s field goals that were assisted. Percentage ranges from 0-100.

home_assists

Returns an int of the total number of assists by the home team.

home_block_percentage

Returns a float of the percentage of 2-point field goals that were blocked by the home team. Percentage ranges from 0-100.

home_blocks

Returns an int of the total number of blocks by the home team.

home_defensive_rating

Returns a float of the average number of points scored per 100 possessions by the away team.

home_defensive_rebound_percentage

Returns a float of the percentage of available defensive rebounds the home team grabbed. Percentage ranges from 0-100.

home_defensive_rebounds

Returns an int of the total number of defensive rebounds by the home team.

home_effective_field_goal_percentage

Returns a float of the home team’s field goal percentage while giving extra weight to 3-point field goals. Percentage ranges from 0-1.

home_field_goal_attempts

Returns an int of the total number of field goal attempts by the home team.

home_field_goal_percentage

Returns a float of the number of field goals made divided by the total number of field goal attempts by the home team. Percentage ranges from 0-1.

home_field_goals

Returns an int of the total number of field goals made by the home team.

home_free_throw_attempt_rate

Returns a float of the average number of free throw attempts per field goal attempt by the home team.

home_free_throw_attempts

Returns an int of the total number of free throw attempts by the home team.

home_free_throw_percentage

Returns a float of the number of free throws made divided by the number of free throw attempts by the home team.

home_free_throws

Returns an int of the total number of free throws made by the home team.

home_losses

Returns an int of the number of games the home team lost after the conclusion of the game.

home_minutes_played

Returns an int of the total number of minutes the team played during the game.

home_offensive_rating

Returns a float of the average number of points scored per 100 possessions by the home team.

home_offensive_rebound_percentage

Returns a float of the percentage of available offensive rebounds the home team grabbed. Percentage ranges from 0-100.

home_offensive_rebounds

Returns an int of the total number of offensive rebounds by the home team.

home_personal_fouls

Returns an int of the total number of personal fouls by the home team.

home_players

Returns a list of BoxscorePlayer class instances for each player on the home team.

home_points

Returns an int of the number of points the home team scored.

home_ranking

Returns an int of the home team’s ranking during the week, or None if they were not ranked.

home_steal_percentage

Returns a float of the percentage of possessions that ended in a steal by the home team. Percentage ranges from 0-100.

home_steals

Returns an int of the total number of steals by the home team.

home_three_point_attempt_rate

Returns a float of the percentage of field goal attempts from 3-point range by the home team. Percentage ranges from 0-1.

home_three_point_field_goal_attempts

Returns an int of the total number of three point field goal attempts by the home team.

home_three_point_field_goal_percentage

Returns a float of the number of three point field goals made divided by the number of three point field goal attempts by the home team. Percentage ranges from 0-1.

home_three_point_field_goals

Returns an int of the total number of three point field goals made by the home team.

home_total_rebound_percentage

Returns a float of the percentage of available rebounds the home team grabbed. Percentage ranges from 0-100.

home_total_rebounds

Returns an int of the total number of rebounds by the home team.

home_true_shooting_percentage

Returns a float of the home team’s true shooting percentage which considers free throws, 2-point field goals, and 3-point field goals. Percentage ranges from 0-1.

home_turnover_percentage

Returns a float of the number of times the home team turned the ball over per 100 possessions.

home_turnovers

Returns an int of the total number of turnovers by the home team.

home_two_point_field_goal_attempts

Returns an int of the total number of two point field goal attempts by the home team.

home_two_point_field_goal_percentage

Returns a float of the number of two point field goals made divided by the number of two point field goal attempts by the home team. Percentage ranges from 0-1.

home_two_point_field_goals

Returns an int of the total number of two point field goals made by the home team.

home_win_percentage

Returns a float of the percentage of games the home team has won after the conclusion of the game. Percentage ranges from 0-1.

home_wins

Returns an int of the number of games the home team won after the conclusion of the game.

location

Returns a string of the name of the venue where the game was played.

losing_abbr

Returns a string of the losing team’s abbreviation, such as ‘INDIANA’ for the Indiana Hoosiers.

losing_name

Returns a string of the losing team’s name, such as ‘Indiana’ Hoosiers’.

pace

Returns a float of the game’s overall pace, measured by the number of possessions per 40 minutes.

summary

Returns a dictionary with two keys, ‘away’ and ‘home’. The value of each key will be a list for each respective team’s score by order of the half, with the first element belonging to the first half, similar to the following:

{
‘away’: [22, 31], ‘home’: [40, 41]

}

winner

Returns a string constant indicating whether the home or away team won.

winning_abbr

Returns a string of the winning team’s abbreviation, such as ‘PURDUE’ for the Purdue Boilermakers.

winning_name

Returns a string of the winning team’s name, such as ‘Purdue Boilermakers’.

class sportsreference.ncaab.boxscore.BoxscorePlayer(player_id, player_name, player_data)[source]

Bases: sportsreference.ncaab.player.AbstractPlayer

Get player stats for an individual game.

Given a player ID, such as ‘carsen-edwards-1’ for Carsen Edwards, their full name, and all associated stats from the Boxscore page in HTML format, parse the HTML and extract only the relevant stats for the specified player and assign them to readable properties.

This class inherits the AbstractPlayer class. As a result, all properties associated with AbstractPlayer can also be read directly from this class.

As this class is instantiated from within the Boxscore class, it should not be called directly and should instead be queried using the appropriate players properties from the Boxscore class.

Parameters:
  • player_id (string) – A player’s ID accorsing to sports-reference.com, such as ‘carsen-edwards-1’ for Carsen Edwards. The player ID can be found by navigating to the player’s stats page and getting the string between the final slash and the ‘.html’ in the URL. In general, the ID is in the format ‘first-last-N’ where ‘first’ is the player’s first name in lowercase, ‘last’ is the player’s last name in lowercase, and ‘N’ is a number starting at ‘1’ for the first time that player ID has been used and increments by 1 for every successive player.
  • player_name (string) – A string representing the player’s first and last name, such as ‘Carsen Edwards’.
  • player_data (string) – A string representation of the player’s HTML data from the Boxscore page. If the player appears in multiple tables, all of their information will appear in one single string concatenated together.
dataframe

Returns a pandas DataFrame containing all other relevant class properties and values for the specified game.

defensive_rating

Returns an int of the player’s defensive rating as measured by the points allowed per 100 possesions.

offensive_rating

Returns an int of the player’s offensive rating as measured by the points produced per 100 possessions.

class sportsreference.ncaab.boxscore.Boxscores(date, end_date=None)[source]

Bases: object

Search for NCAAB games taking place on a particular day.

Retrieve a dictionary which contains a list of all games being played on a particular day. Output includes a link to the boxscore, a boolean value which indicates if the game is between two Division-I teams or not, and the names and abbreviations for both the home teams. If no games are played on a particular day, the list will be empty.

Parameters:
  • date (datetime object) – The date to search for any matches. The month, day, and year are required for the search, but time is not factored into the search.
  • end_date (datetime object) – Optionally specify an end date to iterate until. All boxscores starting from the date specified in the ‘date’ parameter up to and including the boxscores specified in the ‘end_date’ parameter will be pulled. If left empty, or if ‘end_date’ is prior to ‘date’, only the games from the day specified in the ‘date’ parameter will be saved.
games

Returns a dictionary object representing all of the games played on the requested day. Dictionary is in the following format:

{'date' : [  # 'date' is the string date in format 'MM-DD-YYYY'
    {
        'home_name': Name of the home team, such as 'Purdue
                     Boilermakers' (`str`),
        'home_abbr': Abbreviation for the home team, such as
                     'PURDUE' (`str`),
        'away_name': Name of the away team, such as 'Indiana
                     Hoosiers' (`str`),
        'away_abbr': Abbreviation for the away team, such as
                     'INDIANA' (`str`),
        'boxscore': String representing the boxscore URI, such as
                    '2018-01-28-15-indiana' (`str`),
        'non_di': Boolean value which evaluates to True when at
                  least one of the teams does not compete in NCAA
                  Division-I basketball (`bool`),
        'top_25': Boolean value which evaluates to True when at
                  least one of the teams is ranked in the AP Top 25
                  polls (`bool`),
        'winning_name': Full name of the winning team, such as
                        'Purdue Boilermakers' (`str`),
        'winning_abbr': Abbreviation for the winning team, such as
                        'PURDUE' (`str`),
        'losing_name': Full name of the losing team, such as
                       'Indiana Hoosiers' (`str`),
        'losing_abbr': Abbreviation for the losing team, such as
                       'INDIANA' (`str`),
        'home_score': Integer score for the home team (`int`),
        'home_rank': Integer representing the home team's rank
                     (`int`),
        'away_score': Integer score for the away team (`int`),
        'away_rank': Integer representing the away team's rank
                     (`int`)
    },
    { ... },
    ...
    ]
}

If no games were played on ‘date’, the list for [‘date’] will be empty.

Conferences

The Conference module allows conferences to be pulled for any season using the Conferences class. Accessing the class properties exposes various dictionaries containing the team and conference abbreviations as well as other information. To get a list of conference abbreviations for each team, query the team_conference property.

from sportsreference.ncaab.conferences import Conferences

conferences = Conferences()
# Prints a dictionary of the team abbrevation as a key and conference
# abbreviation as the value.
print(conferences.team_conference)

The conferences property can also be queried to provide more details on the teams in every conference.

from sportsreference.ncaab.conferences import Conferences

conferences = Conferences()
# Prints a dictionary where each key is the conference abbreviation and
# each value is a dictionary containing the full conference name as well as
# another dictionary of all teams in the conference, including name and
# abbreviation for each team.
print(conferences.conferences)
class sportsreference.ncaab.conferences.Conference(conference_abbreviation, year=None)[source]

Bases: object

Find teams that participated in a particular conference.

Create a dictionary which includes the names and abbreviations for all teams that participated in a conference during a given year.

Parameters:
  • conference_abbreviation (string) – A string of the requested conference’s abbreviation, such as ‘big-12’.
  • year (string (optional)) – A string of the requested year to pull conference information from. Defaults to the most recent season.
teams

Returns a dictionary of team names and abbreviations where each key is a string of the team abbreviation and each value is a string of the full team name.

class sportsreference.ncaab.conferences.Conferences(year=None)[source]

Bases: object

Get all conferences and teams for a season.

Retrieve a list of all conferences and teams that participated in the conference for each team in the season. The included properties allow flexibility in queries to either get the conference abbreviation for a given team, or get more detailed information including all teams for each conference.

Parameters:year (string (optional)) – A string of the requested year to pull conferences from. Defaults to the most recent season.
conferences

Returns a dictionary of conference names and abbreviations where each key is a string of the abbreviation and each value is a dictionary containing the full conference name and another dictionary with individual team information. The overall dictionary is in the following structure:

{
    abbreviation, ie 'big-12' (str): {
        'name': Full conference name, such as 'Big 12 Conference'
                (str),
        'teams': {
            team abbreviation, such as 'kansas' (str): Full team
                name, such as 'Kansas' (str),
            ...
        }
    },
    ...
}
team_conference

Returns a dictionary of conference abbreviations for each team where each key is a string of the team abbreviation and each value is a string of the conference abbreviation.

Player

The Player module contains an abstract base class that can be inherited by both the BoxscorePlayer and Player classes in the Boxscore and Roster modules, respectively. All of the properties that appear in the AbstractPlayer class can be read from either of the two child classes mentioned above.

class sportsreference.ncaab.player.AbstractPlayer(player_id, player_name, player_data)[source]

Bases: object

Get player information and stats for all seasons.

Given a player ID, such as ‘carsen-edwards-1’ for Carsen Edwards, capture all relevant stats and information like name, height/weight, career three-pointers, last season’s offensive rebounds, offensive points contributed, and much more.

Parameters:
  • player_id (string) – A player’s ID according to sports-reference.com, such as ‘carsen-edwards-1’ for Carsen Edwards. The player ID can be found by navigating to the player’s stats page and getting the string between the final slash and the ‘.html’ in the URL. In general, the ID is in the format ‘first-last-N’ where ‘first’ is the player’s first name in lowercase, ‘last’ is the player’s last name in lowercase, and ‘N’ is a number starting at ‘1’ for the first time that player ID has been used and increments by 1 for every successive player.
  • player_name (string) – A string representing the player’s first and last name, such as ‘Carsen Edwards’.
  • player_data (string) – A string representation of the player’s HTML data from the Boxscore page. If the player appears in multiple tables, all of their information will appear in one single string concatenated togather.
assist_percentage

Returns a float of the percentage of field goals the player assisted while on the floor. Percentage ranges from 0-100.

assists

Returns an int of the total number of assists the player tallied during the season.

block_percentage

Returns a float of the percentage of opposing two-point field goal attempts that were blocked by the player while on the floor. Percentage ranges from 0-100.

blocks

Returns an int of the total number of shots the player blocked during the season.

defensive_rebound_percentage

Returns a float of the percentage of available defensive rebounds the player grabbed. Percentage ranges from 0-100.

defensive_rebounds

Returns an int of the total number of defensive rebounds the player grabbed during the season.

effective_field_goal_percentage

Returns a float of the player’s field goal percentage while giving extra weight to 3-point field goals. Percentage ranges from 0-1.

field_goal_attempts

Returns an int of the total number of field goals the player attempted during the season.

field_goal_percentage

Returns a float of the player’s field goal percentage during the season. Percentage ranges from 0-1.

field_goals

Returns an int of the total number of field goals the player scored.

free_throw_attempt_rate

Returns a float of the number of free throw attempts per field goal attempt.

free_throw_attempts

Returns an int of the total number of free throws the player attempted during the season.

free_throw_percentage

Returns a float of the player’s free throw percentage during the season. Percentage ranges from 0-1.

free_throws

Returns an int of the total number of free throws the player made during the season.

minutes_played

Returns an int of the total number of minutes the player played.

name

Returns a string of the players name, such as ‘Carsen Edwards’.

offensive_rebound_percentage

Returns a float of the percentage of available offensive rebounds the player grabbed. Percentage ranges from 0-100.

offensive_rebounds

Returns an int of the total number of offensive rebounds the player grabbed during the season.

personal_fouls

Returns an int of the total number of personal fouls the player committed during the season.

player_id

Returns a string of the player’s ID on sports-reference, such as ‘carsen-edwards-1’ for Carsen Edwards.

points

Returns an int of the total number of points the player scored during the season.

steal_percentage

Returns a float of the percentage of defensive possessions that ended with the player stealing the ball while on the floor. Percentage ranges from 0-100.

steals

Returns an int of the total number of steals the player tallied during the season.

three_point_attempt_rate

Returns a float of the percentage of field goals that are shot from beyond the 3-point arc. Percentage ranges from 0-1.

three_point_attempts

Returns an int of the total number of three point field goals the player attempted during the season.

three_point_percentage

Returns a float of the player’s three point field goal percentage during the season. Percentage ranges from 0-1.

three_pointers

Returns an int of the total number of three point field goals the player made.

total_rebound_percentage

Returns a float of the percentage of available rebounds the player grabbed, both offensive and defensive. Percentage ranges from 0-100.

total_rebounds

Returns an int of the total number of offensive and defensive rebounds the player grabbed during the season.

true_shooting_percentage

Returns a float of the player’s true shooting percentage which takes into account two and three pointers as well as free throws. Percentage ranges from 0-1.

turnover_percentage

Returns a float of the average number of turnovers per 100 possessions by the player.

turnovers

Returns an int of the total number of times the player turned the ball over during the season for any reason.

two_point_attempts

Returns an int of the total number of two point field goals the player attempted during the season.

two_point_percentage

Returns a float of the player’s two point field goal percentage during the season. Percentage ranges from 0-1.

two_pointers

Returns an int of the total number of two point field goals the player made.

usage_percentage

Returns a float of the percentage of plays the player is involved in while on the floor. Percentage ranges from 0-100.

Rankings

The Rankings module includes the Rankings class which can be used to easily query the NCAAB Men’s Division-I Basketball rankings published by the Associated Press on a week-by-week basis. Different formats can be referenced, ranging from a lightweight dictionary of the most recent rankings containing only the team abbreviation and rank, to a much larger dictionary of all rankings for an entire season with results including full team name and abbreviation, current rank, week number, previous rank, and movement.

from sportsreference.ncaab.rankings import Rankings

rankings = Rankings()
# Prints a dictionary of just the team abbreviation and rank for the current
# week
print(rankings.current)
# Prints more detailed information including previous rank, full name, and
# movement for all teams in current week
print(rankings.current_extended)
# Prints detailed information for all teams for all weeks where rankings
# have been published for the requested season.
print(rankings.complete)
class sportsreference.ncaab.rankings.Rankings(year=None)[source]

Bases: object

Get all Associated Press (AP) rankings on a week-by-week basis.

Grab a list of the rankings published by the Associated Press to easily query the hierarchy of teams each week. The results expose the current and previous rankings as well as the movement for each team in the list.

Parameters:year (string (optional)) – A string of the requested year to pull rankings from. Defaults to the most recent season.
complete

Returns a dictionary where each key is a week number as an int and each value is a list of dictionaries containing the AP rankings for each week. Within each list is a dictionary of team information such as name, abbreviation, rank, and more. Note that the list might not necessarily be in the same order as the rankings.

The overall dictionary has the following structure:

{
    week number, ie 19 (int): [
        {
            'abbreviation': Team's abbreviation, such as 'PURDUE'
                            (str),
            'name': Team's full name, such as 'Purdue' (str),
            'rank': Team's rank for the current week (int),
            'week': Week number for the results, such as 19 (int),
            'date': Date the rankings were released, such as
                    '2017-03-01'. Can also be 'Final' for the final
                    rankings or 'Preseason' for preseason rankings
                    (str),
            'previous': The team's previous rank, if applicable
                        (str),
            'change': The amount the team moved up or down the
                      rankings. Moves up the ladder have a positive
                      number while drops yield a negative number
                      and teams that didn't move have 0 (int)
        },
        ...
    ],
    ...
}
current

Returns a dictionary of the most recent rankings from the Associated Press where each key is a string of the team’s abbreviation and each value is an int of the team’s rank for the current week.

current_extended

Returns a list of dictionaries of the most recent AP rankings. The list is ordered in terms of the ranking so the #1 team will be in the first element and the #25 team will be the last element. Each dictionary has the following structure:

{
    'abbreviation': Team's abbreviation, such as 'PURDUE' (str),
    'name': Team's full name, such as 'Purdue' (str),
    'rank': Team's rank for the current week (int),
    'week': Week number for the results, such as 19 (int),
    'date': Date the rankings were released, such as '2017-03-01'.
            Can also be 'Final' for the final rankings or
            'Preseason' for preseason rankings (str),
    'previous': The team's previous rank, if applicable (str),
    'change': The amount the team moved up or down the rankings.
              Moves up the ladder have a positive number while
              drops yield a negative number and teams that didn't
              move have 0 (int)
}

Roster

The Roster module contains detailed player information, allowing each player to be queried by their player ID using the Player class which has detailed information ranging from career points totals to single-season stats and player height and weight. The following is an example on collecting career information for Carsen Edwards.

from sportsreference.ncaab.roster import Player

carsen_edwards = Player('carsen-edwards-1')
print(carsen_edwards.name)  # Prints 'Carsen Edwards'
print(carsen_edwards.points)  # Prints Edwards' career points total
# Prints a Pandas DataFrame of all relevant stats per season for Edwards
print(carsen_edwards.dataframe)

By default, the player’s career stats are returns whenever a property is called. To get stats for a specific season, call the class instance with the season string. All future property requests will return the season-specific stats.

from sportsreference.ncaab.roster import Player

carsen_edwards = Player('carsen-edwards-1')  # Currently pulling career stats
print(carsen_edwards.points)  # Prints Edwards' CAREER points total
# Prints Edwards' points total only for the 2017-18 season.
print(carsen_edwards('2017-18').points)
# Prints the number of games Edwards played in the 2017-18 season.
print(carsen_edwards.games_played)

After requesting single-season stats, the career stats can be requested again by calling the class without arguments or with the ‘Career’ string passed.

from sportsreference.ncaab.roster import Player

carsen_edwards = Player('carsen-edwards-1')  # Currently pulling career stats
# Prints Edwards' points total only for the 2017-18 season.
print(carsen_edwards('2017-18').points)
print(carsen_edwards('Career').points)  # Prints Edwards' career points total

In addition, the Roster module also contains the Roster class which can be used to pull all players on a team’s roster during a given season and creates instances of the Player class for each team member and adds them to a list to be easily queried.

from sportsreference.ncaab.roster import Roster

purdue = Roster('PURDUE')
for player in purdue.players:
    # Prints the name of all players who played for Purdue in the most
    # recent season.
    print(player.name)
class sportsreference.ncaab.roster.Player(player_id)[source]

Bases: sportsreference.ncaab.player.AbstractPlayer

Get player information and stats for all seasons.

Given a player ID, such as ‘carsen-edwards-1’ for Carsen Edwards, capture all relevant stats and information like name, height/weight, career three-pointers, last season’s offensive rebounds, offensive points contributed, and much more.

This class inherits the AbstractPlayer class. As a result, all properties associated with AbstractPlayer can also be read directly from this class.

By default, the class instance will return the player’s career stats, but single-season stats can be found by calling the instance with the requested season as denoted on sports-reference.com.

Parameters:player_id (string) – A player’s ID according to sports-reference.com, such as ‘carsen-edwards-1’ for Carsen Edwards. The player ID can be found by navigating to the player’s stats page and getting the string between the final slash and the ‘.html’ in the URL. In general, the ID is in the format ‘first-last-N’ where ‘first’ is the player’s first name in lowercase, ‘last’ is the player’s last name in lowercase, and ‘N’ is a number starting at ‘1’ for the first time that player ID has been used and increments by 1 for every successive player.
box_plus_minus

Returns a float of the total number of points per 100 possessions the player contributed in comparison to an average player in the league.

conference

Returns a string of the abbreviation for the conference the team participated in for the requested season.

dataframe

Returns a pandas DataFrame containing all other relevant class properties and values where each index is a different season plus the career stats.

defensive_box_plus_minus

Returns a float of the number of defensive points per 100 possessions the player contributed in comparison to an average player in the league.

defensive_win_shares

Returns a float of the number of wins the player contributed to the team as a result of his defensive plays.

games_played

Returns an int of the number of games the player participated in.

games_started

Returns an int of the number of games the player started.

height

Returns a string of the player’s height in the format “feet-inches”.

offensive_box_plus_minus

Returns a float of the number of offensive points per 100 possessions the player contributed in comparison to an average player in the league.

offensive_win_shares

Returns a float of the number of wins the player contributed to the team as a result of his offensive plays.

player_efficiency_rating

Returns a float of the player’s efficiency rating which represents the player’s relative production level. An average player in the league has an efficiency rating of 15.

points_produced

Returns an int of the number of offensive points the player produced.

position

Returns a string constant of the player’s primary position.

season

Returns a string of the season in the format ‘YYYY-YY’, such as ‘2017-18’. If no season was requested, the career stats will be returned for the player and the season will default to ‘Career’.

team_abbreviation

Returns a string of the abbrevation for the team the player plays for, such as ‘PURDUE’ for Carsen Edwards.

weight

Returns an int of the player’s weight in pounds.

win_shares

Returns a float of the number of wins the player contributed to the team as a result of his offensive and defensive plays.

win_shares_per_40_minutes

Returns a float of the number of wins the player contributed to the team per 40 minutes of playtime. An average player has a contribution of 0.100.

class sportsreference.ncaab.roster.Roster(team, year=None, slim=False)[source]

Bases: object

Get stats for all players on a roster.

Request a team’s roster for a given season and create instances of the Player class for each player, containing a detailed list of the players statistics and information.

Parameters:
  • team (string) – The team’s abbreviation, such as ‘PURDUE’ for the Purdue Boilermakers.
  • year (string (optional)) – The 4-digit year to pull the roster from, such as ‘2018’. If left blank, defaults to the most recent season.
  • slim (boolean (optional)) – Set to True to return a limited subset of player information including the name and player ID for each player as opposed to all of their respective stats which greatly reduces the time to return a response if just the names and IDs are desired. Defaults to False.
players

Returns a list of player instances for each player on the requested team’s roster if the slim property is False when calling the Roster class. If the slim property is True, returns a dictionary where each key is a string of the player’s ID and each value is the player’s first and last name as listed on the roster page.

Schedule

The Schedule module can be used to iterate over all games in a team’s schedule to get game information such as the date, score, result, and more. Each game also has a link to the Boxscore class which has much more detailed information on the game metrics.

from sportsreference.ncaab.schedule import Schedule

purdue_schedule = Schedule('PURDUE')
for game in purdue_schedule:
    print(game.date)  # Prints the date the game was played
    print(game.result)  # Prints whether the team won or lost
    # Creates an instance of the Boxscore class for the game.
    boxscore = game.boxscore
class sportsreference.ncaab.schedule.Game(game_data)[source]

Bases: object

A representation of a matchup between two teams.

Stores all relevant high-level match information for a game in a team’s schedule including date, time, opponent, and result.

Parameters:game_data (string) – The row containing the specified game information.
arena

Returns a string of the name of the arena the game was played at.

boxscore

Returns an instance of the Boxscore class containing more detailed stats on the game.

boxscore_index

Returns a string of the URI for a boxscore which can be used to access or index a game.

dataframe

Returns a pandas DataFrame containing all other class properties and values. The index for the DataFrame is the boxscore string.

dataframe_extended

Returns a pandas DataFrame representing the Boxscore class for the game. This property provides much richer context for the selected game, but takes longer to process compared to the lighter ‘dataframe’ property. The index for the DataFrame is the boxscore string.

date

Returns a string of the game’s date, such as ‘Fri, Nov 10, 2017’.

datetime

Returns a datetime object to indicate the month, day, year, and time the requested game took place.

game

Returns an int of the game’s position in the season. The first game of the season returns 1.

location

Returns a string constant to indicate whether the game was played at the team’s home venue, the opponent’s venue, or at a neutral site.

opponent_abbr

Returns a string of the opponent’s abbreviation, such as ‘PURDUE’ for the Purdue Boilermakers.

opponent_conference

Returns a string of the opponent’s conference, such as ‘Big Ten’ for a team participating in the Big Ten Conference. If the team is not a Division-I school, a string constant for non-majors is returned.

opponent_name

Returns a string of the opponent’s name, such as the ‘Purdue Boilermakers’.

opponent_rank

Returns a string of the opponent’s rank when the game was played and None if the team was unranked.

overtimes

Returns an int of the number of overtimes that were played during the game and 0 if the game finished at the end of regulation time.

points_against

Returns an int of the number of points the team allowed during the game.

points_for

Returns an int of the number of points the team scored during the game.

result

Returns a string constant to indicate whether the team won or lost the game.

season_losses

Returns an int of the number of games the team has lost after the conclusion of the requested game.

season_wins

Returns an int of the number of games the team has won after the conclusion of the requested game.

streak

Returns a string of the team’s win streak at the conclusion of the requested game. Streak is in the format ‘[W|L] #’ (ie. ‘W 3’ indicates a 3-game winning streak while ‘L 2’ indicates a 2-game losing streak.

time

Returns a string to indicate the time the game started, such as ‘9:00 pm/est’.

type

Returns a string constant to indicate whether the game was played during the regular season or in the post season.

class sportsreference.ncaab.schedule.Schedule(abbreviation, year=None)[source]

Bases: object

An object of the given team’s schedule.

Generates a team’s schedule for the season including wins, losses, and scores if applicable.

Parameters:
  • abbreviation (string) – A team’s short name, such as ‘PURDUE’ for the Purdue Boilermakers.
  • year (string (optional)) – The requested year to pull stats from.
dataframe

Returns a pandas DataFrame where each row is a representation of the Game class. Rows are indexed by the boxscore string.

dataframe_extended

Returns a pandas DataFrame where each row is a representation of the Boxscore class for every game in the schedule. Rows are indexed by the boxscore string. This property provides much richer context for the selected game, but takes longer to process compared to the lighter ‘dataframe’ property.

Teams

The Teams module exposes information for all NCAAB teams including the team name and abbreviation, the number of games they won during the season, the total number of shots they’ve blocked, and much more.

from sportsreference.ncaab.teams import Teams

teams = Teams()
for team in teams:
    print(team.name)  # Prints the team's name
    print(team.blocks)  # Prints the number of shots the team blocked

Each Team instance contains a link to the Schedule class which enables easy iteration over all games for a particular team. A Pandas DataFrame can also be queried to easily grab all stats for all games.

from sportsreference.ncaab.teams import Teams

teams = Teams()
for team in teams:
    schedule = team.schedule  # Returns a Schedule instance for each team
    # Returns a Pandas DataFrame of all metrics for all game Boxscores for
    # a season.
    df = team.schedule.dataframe_extended

Lastly, each Team instance also contains a link to the Roster class which enables players from the team to be easily queried. Each Roster instance contains detailed stats and information for each player on the team.

from sportsreference.ncaab.teams import Teams

for team in Teams():
    roster = team.roster  # Gets each team's roster
    for player in roster.players:
        print(player.name)  # Prints each players name on the roster
class sportsreference.ncaab.teams.Team(team_data, team_conference=None, year=None)[source]

Bases: object

An object containing all of a team’s season information.

Finds and parses all team stat information and identifiers, such as full and short names, and sets them as properties which can be directly read from for easy reference.

Parameters:
  • team_data (string) – A string containing all of the rows of stats for a given team. If multiple tables are being referenced, this will be comprised of multiple rows in a single string.
  • team_conference (string (optional)) – A string of the team’s conference abbreviation, such as ‘big-12’.
  • year (string (optional)) – The requested year to pull stats from.
abbreviation

Returns a string of the team’s short name, such as ‘PURDUE’ for the Purdue Boilermakers.

assist_percentage

Returns a float of the percentage of field goals that were assisted. Percentage ranges from 0-100.

assists

Returns an int of the total number of assists during the season.

away_losses

Returns an int of the total number of away games the team lost during the season.

away_wins

Returns an int of the total number of away games the team won during the season.

block_percentage

Returns a float of the percentage of 2-point field goals by the opponent that were blocked. Percentage ranges from 0-100.

blocks

Returns an int of the total number of blocks during the season.

conference

Returns a string of the team’s conference abbreviation, such as ‘big-12’ for the Big 12 Conference.

conference_losses

Returns an int of the total number of conference games the team lost during the season.

conference_wins

Returns an int of the total number of conference games the team won during the season.

dataframe

Returns a pandas DataFrame containing all other class properties and values. The index for the DataFrame is the string abbreviation of the team, such as ‘PURDUE’.

defensive_rebounds

Returns an int of the total number of defensive rebounds during the season.

effective_field_goal_percentage

Returns a float of the field goal percentage while giving extra weight to 3-point field goals. Percentage ranges from 0-1.

field_goal_attempts

Returns an int of the total number of field goal attempts during the season.

field_goal_percentage

Returns a float of the number of field goals made divided by the total number of field goal attempts. Percentage ranges from 0-1.

field_goals

Returns an int of the total number of field goals made during the season.

free_throw_attempt_rate

Returns a float of the average number of free throw attempts per field goal attempt.

free_throw_attempts

Returns an int of the total number of free throw attempts during the season.

free_throw_percentage

Returns a float of the number of free throws made divided by the number of free throw attempts during the season.

free_throws

Returns an int of the total number of free throws made during the season.

free_throws_per_field_goal_attempt

Returns a float of the number of free throws per field goal attempt.

games_played

Returns an int of the total number of games the team has played during the season.

home_losses

Returns an int of the total number of home games the team lost during the season.

home_wins

Returns an int of the total number of home games the team won during the season.

losses

Returns an int of the total number of games the team lost during the season.

minutes_played

Returns an int of the total number of minutes played by the team during the season.

name

Returns a string of the team’s full name, such as ‘Purdue Boilermakers’.

net_rating

Returns a float of the net team rating which is equivalent to the difference between the offensive rating and the defensive (or the opponent’s offensive) rating. Positive values indicate teams that score more points than they allow per 100 possessions.

offensive_rating

Returns a float of the average number of points scored per 100 possessions.

offensive_rebound_percentage

Returns a float of the percentage of available offensive rebounds a team grabbed. Percentage ranges from 0-100.

offensive_rebounds

Returns an int of the total number of offensive rebounds during the season.

opp_assist_percentage

Returns a float of the percentage of the opponent’s field goals that were assisted. Percentage ranges from 0-100.

opp_assists

Returns an int of the total number of assists during the season by opponents.

opp_block_percentage

Returns a float of the percentage of 2-point field goals that were blocked by the opponent. Percentage ranges from 0-100.

opp_blocks

Returns an int of the total number of blocks during the season by opponents.

opp_defensive_rebounds

Returns an int of the total number of defensive rebounds during the season by opponents.

opp_effective_field_goal_percentage

Returns a float of the opponent’s field goal percentage while giving extra weight to 3-point field goals. Percentage ranges from 0-1.

opp_field_goal_attempts

Returns an int of the total number of field goal attempts during the season by opponents.

opp_field_goal_percentage

Returns a float of the number of field goals made divided by the total number of field goal attempts by opponents. Percentage ranges from 0-1.

opp_field_goals

Returns an int of the total number of field goals made during the season by opponents.

opp_free_throw_attempt_rate

Returns a float of the average number of free throw attempts per field goal attempt by the opponent.

opp_free_throw_attempts

Returns an int of the total number of free throw attempts during the season by opponents.

opp_free_throw_percentage

Returns a float of the number of free throws made divided by the number of free throw attempts during the season by opponents.

opp_free_throws

Returns an int of the total number of free throws made during the season by opponents.

opp_free_throws_per_field_goal_attempt

Returns a float of the number of free throws per field goal attempt by the opponent.

opp_offensive_rating

Returns a float of the average number of points scored per 100 possessions by the opponent. This is equivalent to the team’s defensive rating as it is the number of points the team allows per 100 possessions by the opponent.

opp_offensive_rebound_percentage

Returns a float of the percentage of available offensive rebounds the opponent grabbed. Percentage ranges from 0-100.

opp_offensive_rebounds

Returns an int of the total number of offensive rebounds during the season by opponents.

opp_personal_fouls

Returns an int of the total number of personal fouls during the season by opponents.

opp_points

Returns an int of the total number of points opponents have scored during the season.

opp_steal_percentage

Returns a float of the percentage of possessions that ended in a steal by the opponent. Percentage ranges from 0-100.

opp_steals

Returns an int of the total number of steals during the season by opponents.

opp_three_point_attempt_rate

Returns a float of the percentage of field goal attempts from 3-point range by the opponent. Percentage ranges from 0-1.

opp_three_point_field_goal_attempts

Returns an int of the total number of three point field goal attempts during the season by opponents.

opp_three_point_field_goal_percentage

Returns a float of the number of three point field goals made divided by the number of three point field goal attempts by opponents. Percentage ranges from 0-1.

opp_three_point_field_goals

Returns an int of the total number of three point field goals made during the season by opponents.

opp_total_rebound_percentage

Returns a float of the percentage of available rebounds the opponent grabbed. Percentage ranges from 0-100.

opp_total_rebounds

Returns an int of the total number of rebounds during the season by opponents.

opp_true_shooting_percentage

Returns a float of the opponent’s true shooting percentage which considers free throws, 2-point field goals, and 3-point field goals. Percentage ranges from 0-1.

opp_turnover_percentage

Returns a float of the number of times the opponent turned the ball over per 100 possessions.

opp_turnovers

Returns an int of the total number of turnovers during the season by opponents.

opp_two_point_field_goal_attempts

Returns an int of the total number of two point field goal attempts during the season by opponents.

opp_two_point_field_goal_percentage

Returns a float of the number of two point field goals made divided by the number of two point field goal attempts by opponents. Percentage ranges from 0-1.

opp_two_point_field_goals

Returns an int of the total number of two point field goals made during the season by opponents.

pace

Returns a float of the average number of possessions per 40 minutes.

personal_fouls

Returns an int of the total number of personal fouls during the season.

points

Returns an int of the total number of points the team scored during the season.

roster

Returns an instance of the Roster class containing all players for the team during the season with all career stats.

schedule

Returns an instance of the Schedule class containing the team’s complete schedule for the season.

simple_rating_system

Returns a float of the team’s average point differential compared to the strength of schedule. Higher values indicate stronger teams. An average team is denoted with 0.0. Negative numbers are comparatively worse than average.

steal_percentage

Returns a float of the percentage of opponent possessions that ended in a steal. Percentage ranges from 0-100.

steals

Returns an int of the total number of steals during the season.

strength_of_schedule

Returns a float of the team’s strength of schedule based on the points above and below average. An average strength of schedule is denoted with 0.0. Negative numbers are comparatively easier than average.

three_point_attempt_rate

Returns a float of the percentage of field goal attempts from 3-point range. Percentage ranges from 0-1.

three_point_field_goal_attempts

Returns an int of the total number of three point field goal attempts during the season.

three_point_field_goal_percentage

Returns a float of the number of three point field goals made divided by the number of three point field goal attempts. Percentage ranges from 0-1.

three_point_field_goals

Returns an int of the total number of three point field goals made during the season.

total_rebound_percentage

Returns a float of the percentage of available rebounds a team grabbed. Percentage ranges from 0-100.

total_rebounds

Returns an int of the total number of rebounds during the season.

true_shooting_percentage

Returns a float of the team’s true shooting percentage which considers free throws, 2-point field goals, and 3-point field goals. Percentage ranges from 0-1.

turnover_percentage

Returns a float of the number of times the team turned the ball over per 100 possessions.

turnovers

Returns an int of the total number of turnovers during the season.

two_point_field_goal_attempts

Returns an int of the total number of two point field goal attempts during the season.

two_point_field_goal_percentage

Returns a float of the number of two point field goals made divided by the number of two point field goal attempts. Percentage ranges from 0-1.

two_point_field_goals

Returns an int of the total number of two point field goals made during the season.

win_percentage

Returns a float of the number of wins divided by the number of games played during the season. Percentage ranges from 0-1.

wins

Returns an int of the total number of games the team won during the season.

class sportsreference.ncaab.teams.Teams(year=None)[source]

Bases: object

A list of all NCAA Men’s Basketball teams and their stats in a given year.

Finds and retrieves a list of all NCAA Men’s Basketball teams from www.sports-reference.com and creates a Team instance for every team that participated in the league in a given year. The Team class comprises a list of all major stats and a few identifiers for the requested season.

Parameters:year (string (optional)) – The requested year to pull stats from.
dataframes

Returns a pandas DataFrame where each row is a representation of the Team class. Rows are indexed by the team abbreviation.