Basketball - uwaggs/usportspy GitHub Wiki
Basketball Functions
The usportspy package provides various functions to retrieve basketball-related data, such as schedules, team box scores, player box scores, and play-by-play data.
basketball_get_schedule
Fetches the basketball schedule for the specified gender.
Parameters:
gender(str): Specifies the gender of the teams. Must be either"m"or"w".
Returns:
pd.DataFrame: A DataFrame containing the basketball schedule. The columns of the returned DataFrame are:league,season,game_id,date,exhibition,conference,playoffs,championship,home_team,away_team,home_score,away_score,game_link.
Example:
from usportspy import basketball_get_schedule
# Get the schedule for male teams
male_schedule = basketball_get_schedule("m")
print(male_schedule.head())
# Get the schedule for female teams
female_schedule = basketball_get_schedule("w")
print(female_schedule.head())
Expected output:
league season game_id date exhibition ... home_team away_team home_score away_score game_link
0 mbkb 2009-10 NaN 2009-09-05 True ... york tennesseechattanooga 71 78 NaN
1 mbkb 2009-10 NaN 2009-10-09 True ... york findlayoilers 66 94 NaN
2 mbkb 2009-10 20091010_3re4 2009-10-10 True ... brock findlay 82 86 https://en.usports.ca/sports/mbkb/2009-10/boxs...
3 mbkb 2009-10 20091016_bzve 2009-10-16 True ... brock dalhousie 68 79 https://en.usports.ca/sports/mbkb/2009-10/boxs...
4 mbkb 2009-10 20091017_eu0v 2009-10-17 True ... brock winnipeg 83 86 https://en.usports.ca/sports/mbkb/2009-10/boxs...
[5 rows x 13 columns]
league season game_id date exhibition conference playoffs championship home_team away_team home_score away_score game_link
0 wbkb 2009-10 NaN 2009-10-03 True False False False brock niagaraall-stars 84 64 NaN
1 wbkb 2009-10 NaN 2009-10-09 True False False False york western 52 69 NaN
2 wbkb 2009-10 NaN 2009-10-10 True False False False brock senecacollege 80 38 NaN
3 wbkb 2009-10 NaN 2009-10-16 True False False False brock upei 76 51 NaN
4 wbkb 2009-10 NaN 2009-10-17 True False False False dalhousie york 69 54 NaN
basketball_get_team_box_score
Fetches the team box score data for basketball teams over specified seasons.
Parameters:
gender(str): Specifies the gender of the teams. Must be either"m"or"w".seasons(list of int, optional): List of seasons (starting year) to filter by. If nothing is provided, data for all seasons will be returned.
Returns:
pd.DataFrame: A DataFrame containing the team box scores. The columns of the returned DataFrame are:team,field_goals_made,field_goals_attempted,field_goal_percent,three_pointers_made,three_pointers_attempted,three_point_percentage,free_throws_made,free_throws_attempted,free_throw_percent,rebounds,assists,turnovers,points_off_turnovers,second_chance_points,points_in_the_paint,fastbreak_points,bench_points,largest_lead,time_of_largest_lead,ties,lead_changes,team_links,team_status,date,sport,link,game_id,season.
Example:
from usportspy import basketball_get_team_box_score
# Get team box scores for male teams for the 2018 and 2019 seasons
male_team_box_score = basketball_get_team_box_score("m", [2018, 2019])
print(male_team_box_score.head())
# Get team box scores for female teams for the 2018 and 2019 seasons
female_team_box_score = basketball_get_team_box_score("w", [2018, 2019])
print(female_team_box_score.head())
Expected output:
team field_goals_made field_goals_attempted field_goal_percent ... sport link game_id season
0 Mississippi 40 69 0.580 ... mbkb https://en.usports.ca/sports/mbkb/2018-19/boxs... 20180805_5fk9 2018-19
1 McGill 18 63 0.286 ... mbkb https://en.usports.ca/sports/mbkb/2018-19/boxs... 20180805_5fk9 2018-19
2 OleMiss 33 65 0.508 ... mbkb https://en.usports.ca/sports/mbkb/2018-19/boxs... 20180806_awdh 2018-19
3 Concordia 28 62 0.452 ... mbkb https://en.usports.ca/sports/mbkb/2018-19/boxs... 20180806_awdh 2018-19
4 Cincinnati 25 58 0.431 ... mbkb https://en.usports.ca/sports/mbkb/2018-19/boxs... 20180807_pse7 2018-19
[5 rows x 29 columns]
team field_goals_made field_goals_attempted field_goal_percent ... sport link game_id season
0 PeoplesRepofChinaUnder 32 70 0.457 ... wbkb https://en.usports.ca/sports/wbkb/2018-19/boxs... 20180906_1u5z 2018-19
1 UBC 25 54 0.463 ... wbkb https://en.usports.ca/sports/wbkb/2018-19/boxs... 20180906_1u5z 2018-19
2 Algoma 20 49 0.408 ... wbkb https://en.usports.ca/sports/wbkb/2018-19/boxs... 20180920_g0rt 2018-19
3 Lakehead 35 88 0.398 ... wbkb https://en.usports.ca/sports/wbkb/2018-19/boxs... 20180920_g0rt 2018-19
4 Algoma 17 54 0.315 ... wbkb https://en.usports.ca/sports/wbkb/2018-19/boxs... 20180921_udlr 2018-19
[5 rows x 29 columns]
basketball_get_player_box_score
Fetches the player box score data for basketball players over specified seasons.
Parameters:
gender(str): Specifies the gender of the teams. Must be either"m"or"w".seasons(list of int, optional): List of seasons (starting year) to filter by. If nothing is provided, data for all seasons will be returned.
Returns:
pd.DataFrame: A DataFrame containing the player box scores. The columns of the returned DataFrame are:period,team,team_status,role,jersey_number,name,minutes_played,field_goals_made,field_goals_attempted,three_pointers_made,three_pointers_attempted,free_throws_made,free_throws_attempted,offensive_rebounds,defensive_rebounds,total_rebounds,assists,steals,blocks,turnovers,personal_fouls,points,player_links,date,sport,link,game_id,season.
Example:
from usportspy import basketball_get_player_box_score
# Get player box scores for male teams for the 2018 and 2019 seasons
male_player_box_score = basketball_get_player_box_score("m", [2018, 2019])
print(male_player_box_score.head())
# Get player box scores for female teams for the 2018 and 2019 seasons
female_player_box_score = basketball_get_player_box_score("w", [2018, 2019])
print(female_player_box_score.head())
Expected output:
period team team_status role jersey_number ... date sport link game_id season
0 1st Qtr Mississippi away STARTER 0.0 ... 2018-08-05 mbkb https://en.usports.ca/sports/mbkb/2018-19/boxs... 20180805_5fk9 2018-19
1 1st Qtr Mississippi away STARTER 2.0 ... 2018-08-05 mbkb https://en.usports.ca/sports/mbkb/2018-19/boxs... 20180805_5fk9 2018-19
2 1st Qtr Mississippi away STARTER 3.0 ... 2018-08-05 mbkb https://en.usports.ca/sports/mbkb/2018-19/boxs... 20180805_5fk9 2018-19
3 1st Qtr Mississippi away STARTER 4.0 ... 2018-08-05 mbkb https://en.usports.ca/sports/mbkb/2018-19/boxs... 20180805_5fk9 2018-19
4 1st Qtr Mississippi away STARTER 12.0 ... 2018-08-05 mbkb https://en.usports.ca/sports/mbkb/2018-19/boxs... 20180805_5fk9 2018-19
[5 rows x 28 columns]
period team team_status role jersey_number ... date sport link game_id season
0 1st Qtr PeoplesRepofChinaUnder away STARTER 12.0 ... 2018-09-06 wbkb https://en.usports.ca/sports/wbkb/2018-19/boxs... 20180906_1u5z 2018-19
1 1st Qtr PeoplesRepofChinaUnder away STARTER 15.0 ... 2018-09-06 wbkb https://en.usports.ca/sports/wbkb/2018-19/boxs... 20180906_1u5z 2018-19
2 1st Qtr PeoplesRepofChinaUnder away STARTER 16.0 ... 2018-09-06 wbkb https://en.usports.ca/sports/wbkb/2018-19/boxs... 20180906_1u5z 2018-19
3 1st Qtr PeoplesRepofChinaUnder away STARTER 7.0 ... 2018-09-06 wbkb https://en.usports.ca/sports/wbkb/2018-19/boxs... 20180906_1u5z 2018-19
4 1st Qtr PeoplesRepofChinaUnder away STARTER 8.0 ... 2018-09-06 wbkb https://en.usports.ca/sports/wbkb/2018-19/boxs... 20180906_1u5z 2018-19
[5 rows x 28 columns]
basketball_get_pbp
Fetches the play-by-play (PBP) data for basketball games over specified seasons.
Parameters:
gender(str): Specifies the gender of the teams. Must be either"m"or"w".seasons(list of int, optional): List of seasons (starting year) to filter by. If nothing is provided, data for all seasons will be returned.
Returns:
pd.DataFrame: A DataFrame containing the play-by-play data. The columns of the returned DataFrame are:quarter,team,team_status,time,away_score,home_score,last_name,first_name,action,date,sport,link,game_id,season.
Example:
from usportspy import basketball_get_pbp
# Get PBP data for male teams for the 2018 and 2019 seasons
male_pbp = basketball_get_pbp("m", [2018, 2019])
print(male_pbp.head())
# Get PBP data for female teams for the 2018 and 2019 seasons
female_pbp = basketball_get_pbp("w", [2018, 2019])
print(female_pbp.head())
Expected output:
quarter team team_status time away_score ... date sport link game_id season
0 1 Mississippi away 10:00 0.0 ... 2018-08-05 mbkb https://en.usports.ca/sports/mbkb/2018-19/boxs... 20180805_5fk9 2018-19
1 1 McGill home 10:00 0.0 ... 2018-08-05 mbkb https://en.usports.ca/sports/mbkb/2018-19/boxs... 20180805_5fk9 2018-19
2 1 McGill home 10:00 0.0 ... 2018-08-05 mbkb https://en.usports.ca/sports/mbkb/2018-19/boxs... 20180805_5fk9 2018-19
3 1 Mississippi away 09:57 0.0 ... 2018-08-05 mbkb https://en.usports.ca/sports/mbkb/2018-19/boxs... 20180805_5fk9 2018-19
4 1 Mississippi away 09:44 2.0 ... 2018-08-05 mbkb https://en.usports.ca/sports/mbkb/2018-19/boxs... 20180805_5fk9 2018-19
[5 rows x 14 columns]
quarter team team_status time away_score ... date sport link game_id season
0 1 PeoplesRepofChinaUnder away 09:45 0.0 ... 2018-09-06 wbkb https://en.usports.ca/sports/wbkb/2018-19/boxs... 20180906_1u5z 2018-19
1 1 UBC home 09:45 0.0 ... 2018-09-06 wbkb https://en.usports.ca/sports/wbkb/2018-19/boxs... 20180906_1u5z 2018-19
2 1 PeoplesRepofChinaUnder away 09:27 0.0 ... 2018-09-06 wbkb https://en.usports.ca/sports/wbkb/2018-19/boxs... 20180906_1u5z 2018-19
3 1 UBC home 09:27 0.0 ... 2018-09-06 wbkb https://en.usports.ca/sports/wbkb/2018-19/boxs... 20180906_1u5z 2018-19
4 1 UBC home 09:27 0.0 ... 2018-09-06 wbkb https://en.usports.ca/sports/wbkb/2018-19/boxs... 20180906_1u5z 2018-19
[5 rows x 14 columns]