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.

Functions

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: date, away, away_score, home, home_score, status, notes, month, box_scores, conference, division, exhibition, postseason, and season.

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:

      date                  away  away_score        home  home_score       status notes         month box_scores  conference  division  exhibition  postseason   season
0  Thu. 24                Guelph         NaN       Brock         NaN  8:00 PM EDT   NaN  October 2024        NaN           1         0           0           0  2024-25
1  Fri. 25               Toronto         NaN  Laurentian         NaN  8:00 PM EDT   NaN  October 2024        NaN           1         0           0           0  2024-25
2  Fri. 25  Toronto Metropolitan         NaN   Nipissing         NaN  8:00 PM EDT   NaN  October 2024        NaN           1         0           0           0  2024-25
3  Fri. 25               Laurier         NaN        York         NaN  8:00 PM EDT   NaN  October 2024        NaN           1         0           0           0  2024-25
4  Fri. 25               Windsor         NaN      Ottawa         NaN  8:00 PM EDT   NaN  October 2024        NaN           1         0           0           0  2024-25


      date                  away  away_score           home  home_score       status  ...                                         box_scores conference division  exhibition  postseason   season
0   Tue. 6  South Carolina State        70.0           UQAM        65.0        Final  ...  https://en.usports.ca/sports/wbkb/2024-25/boxs...          0        0           1           0  2024-25
1   Wed. 7  South Carolina State        69.0          Laval        73.0        Final  ...  https://en.usports.ca/sports/wbkb/2024-25/boxs...          0        0           1           0  2024-25
2   Thu. 8  South Carolina State         NaN      Concordia         NaN  6:00 PM EDT  ...                                                NaN          0        0           1           0  2024-25
3  Sat. 17            Assumption         NaN      Concordia         NaN  6:00 PM EDT  ...                                                NaN          0        0           1           0  2024-25
4  Fri. 20                  StFX         NaN  Mount Allison         NaN          TBA  ...                                                NaN          0        0           1           0  2024-25

[5 rows x 14 columns]

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: field_goals_made, field_goals_attempted, field_goal_percentage, three_point_field_goals_made, three_point_field_goals_attempted, three_point_field_goal_percentage, free_throws_made, free_throws_attempted, free_throw_percentage, rebounds, assists, turnovers, points_off_turnovers, second_chance_points, points_in_the_paint, fastbreak_points, bench_points, largest_lead, trends, team_name, game_id, date, q1, q2, q3, q4, total, time_of_largest_lead, ot, x2ot, x3ot, season, and season_type.

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:

   field_goals_made  field_goals_attempted field_goal_percentage  three_point_field_goals_made  three_point_field_goals_attempted  ...  ot  x2ot  x3ot   season  season_type
0                26                     69                 37.7%                            10                                 29  ... NaN   NaN   NaN  2018-19            p
1                37                     72                 51.4%                             6                                 23  ... NaN   NaN   NaN  2018-19            p
2                19                     56                 33.9%                             5                                 18  ... NaN   NaN   NaN  2018-19            p
3                25                     71                 35.2%                             8                                 29  ... NaN   NaN   NaN  2018-19            p
4                29                     70                 41.4%                             5                                 19  ... NaN   NaN   NaN  2018-19            p

[5 rows x 33 columns]


   field_goals_made  field_goals_attempted field_goal_percentage  three_point_field_goals_made  three_point_field_goals_attempted  ...  ot  x2ot  x3ot   season  season_type
0                22                     81                 27.2%                             2                                 20  ... NaN   NaN   NaN  2018-19            p
1                38                     88                 43.2%                             9                                 25  ... NaN   NaN   NaN  2018-19            p
2                28                     59                 47.5%                             8                                 17  ... NaN   NaN   NaN  2018-19            p
3                31                     73                 42.5%                             6                                 18  ... NaN   NaN   NaN  2018-19            p
4                23                     63                 36.5%                             7                                 18  ... NaN   NaN   NaN  2018-19            p

[5 rows x 33 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: player, min, fgm, fga, three_pm, three_pa, ftm, fta, oreb, dreb, reb, ast, stl, blk, to, pf, pts, starter, player_number, player_links, date, game_id, team_name, season, and season_type.

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:

           player   min  fgm   fga  three_pm  three_pa  ftm  fta  oreb  dreb   reb  ...   to   pf   pts  starter  player_number  player_links                        date        game_id team_name   season season_type
0    Keiran Zziwa  23.0  0.0   5.0       0.0       3.0  1.0  2.0   0.0   0.0   0.0  ...  4.0  2.0   1.0        1            1.0           NaN  February 7, 2019  - 7:00pm  20190207_q3pq  Manitoba  2018-19           p
1  Rashawn Browne  35.0  8.0  17.0       3.0       8.0  4.0  4.0   0.0   3.0   3.0  ...  6.0  1.0  23.0        1            4.0           NaN  February 7, 2019  - 7:00pm  20190207_q3pq  Manitoba  2018-19           p
2    James Wagner  40.0  5.0  12.0       0.0       2.0  6.0  7.0   5.0   5.0  10.0  ...  1.0  4.0  16.0        1           10.0           NaN  February 7, 2019  - 7:00pm  20190207_q3pq  Manitoba  2018-19           p
3    Andre Arruda  34.0  6.0  19.0       1.0       6.0  2.0  2.0   3.0   2.0   5.0  ...  2.0  3.0  15.0        1           11.0           NaN  February 7, 2019  - 7:00pm  20190207_q3pq  Manitoba  2018-19           p
4  Cameron O'Hara  13.0  0.0   2.0       0.0       0.0  0.0  0.0   0.0   2.0   2.0  ...  0.0  0.0   0.0        1           13.0           NaN  February 7, 2019  - 7:00pm  20190207_q3pq  Manitoba  2018-19           p

[5 rows x 25 columns]


             player   min  fgm   fga  three_pm  three_pa  ftm  fta  oreb  dreb  reb  ...   to   pf   pts  starter  team_name  player_number  player_links                         date        game_id   season season_type
0    Taylor Randall  31.0  5.0  23.0       0.0       7.0  5.0  5.0   1.0   0.0  1.0  ...  4.0  1.0  15.0        1   Manitoba            3.0           NaN  February 8, 2019  - 6:00 pm  20190208_pfog  2018-19           p
1     Tianna Mighty  13.0  0.0   2.0       0.0       0.0  0.0  0.0   1.0   1.0  2.0  ...  0.0  2.0   0.0        1   Manitoba            5.0           NaN  February 8, 2019  - 6:00 pm  20190208_pfog  2018-19           p
2     Emma Thompson  20.0  0.0   5.0       0.0       3.0  0.0  0.0   0.0   2.0  2.0  ...  0.0  2.0   0.0        1   Manitoba            8.0           NaN  February 8, 2019  - 6:00 pm  20190208_pfog  2018-19           p
3  Nicole Konieczny  33.0  6.0  18.0       1.0       4.0  4.0  6.0   0.0   8.0  8.0  ...  1.0  1.0  17.0        1   Manitoba           10.0           NaN  February 8, 2019  - 6:00 pm  20190208_pfog  2018-19           p
4     Claire Harvey  21.0  3.0  10.0       0.0       1.0  0.0  1.0   4.0   5.0  9.0  ...  3.0  2.0   6.0        1   Manitoba           11.0           NaN  February 8, 2019  - 6:00 pm  20190208_pfog  2018-19           p

[5 rows x 25 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: time, away, away_score, home_score, home, quarter, game_id, away_team, home_team, season, and season_type.

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:

    time                        away  away_score  home_score                             home quarter        game_id away_team home_team   season season_type
0  09:51                         NaN           0           2  AMBANZA,NARCISSE made jump shot     1st  20190207_q3pq  Manitoba  Winnipeg  2018-19           p
1  09:45    Turnover by ARRUDA,ANDRE           0           2                              NaN     1st  20190207_q3pq  Manitoba  Winnipeg  2018-19           p
2  09:43                         NaN           0           2             Steal by TARVER,SEAN     1st  20190207_q3pq  Manitoba  Winnipeg  2018-19           p
3  09:30                         NaN           0           4  AMBANZA,NARCISSE made jump shot     1st  20190207_q3pq  Manitoba  Winnipeg  2018-19           p
4  09:28  Turnover by BROWNE,RASHAWN           0           4                              NaN     1st  20190207_q3pq  Manitoba  Winnipeg  2018-19           p


    time away  away_score  home_score                                     home quarter        game_id away_team   home_team   season season_type
0  09:50  NaN         0.0         0.0  FRITZKE,DANIELLE missed 3-pt. jump shot     1st  20190208_pfog  Manitoba  Lethbridge  2018-19           p
1  09:50  NaN         0.0         0.0        ZAROWNY,JESSICA offensive rebound     1st  20190208_pfog  Manitoba  Lethbridge  2018-19           p
2  09:39  NaN         0.0         0.0             BOSCH,KACIE missed jump shot     1st  20190208_pfog  Manitoba  Lethbridge  2018-19           p
3  09:39  NaN         0.0         0.0            BOSCH,KACIE offensive rebound     1st  20190208_pfog  Manitoba  Lethbridge  2018-19           p
4  09:26  NaN         0.0         0.0           FOMINA,ASNATE missed jump shot     1st  20190208_pfog  Manitoba  Lethbridge  2018-19           p