Soccer - uwaggs/usportspy GitHub Wiki

Soccer Functions

The usportspy package offers functions to retrieve various data related to Soccer, including schedules, team and player box scores, and play-by-play data.

Functions

soccer_get_schedule

Fetches the schedule for Soccer games based on gender.

Parameters:

  • gender (str): Must be "m" or "w".

Returns:

  • pd.DataFrame: A DataFrame containing the schedule for Soccer games. 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 soccer_get_schedule

# Get the schedule for male Soccer
schedule_male = soccer_get_schedule("m")
print(schedule_male.head())

# Get the schedule for female Soccer
schedule_female = soccer_get_schedule("w")
print(schedule_female.head())

Expected output:

      date      away  away_score       home  home_score       status             notes        month box_scores  conference  division  exhibition  postseason   season
0  Sat. 17   Moncton         NaN       StFX         NaN  3:00 PM ADT  (Non-Conference)  August 2024        NaN           0         0           1           0  2024-25
1  Sun. 18    Acadia         NaN  Concordia         NaN          TBA               NaN  August 2024        NaN           0         0           0           0  2024-25
2  Thu. 22  Memorial         NaN  Concordia         NaN          TBA               NaN  August 2024        NaN           0         0           0           0  2024-25
3  Fri. 23    Algoma         NaN     Acadia         NaN  6:00 PM ADT      (Pre-Season)  August 2024        NaN           0         0           1           0  2024-25
4  Fri. 23      UNBC         NaN        UFV         NaN  6:00 PM PDT               NaN  August 2024        NaN           1         0           0           0  2024-25


      date        away  away_score         home  home_score        status             notes        month box_scores  conference  division  exhibition  postseason   season
0   Wed. 7     MacEwan         NaN  Mount Royal         NaN   2:00 PM MDT               NaN  August 2024        NaN           0         0           1           0  2024-25
1  Tue. 13        UNBC         NaN      MacEwan         NaN  11:00 AM MDT               NaN  August 2024        NaN           0         0           1           0  2024-25
2  Wed. 14  Lethbridge         NaN      MacEwan         NaN   4:00 PM MDT               NaN  August 2024        NaN           0         0           1           0  2024-25
3  Sat. 17     Moncton         NaN         StFX         NaN   5:00 PM ADT  (Non-Conference)  August 2024        NaN           0         0           1           0  2024-25
4  Mon. 19     Queen's         NaN    Concordia         NaN           TBA               NaN  August 2024        NaN           0         0           0           0  2024-25

soccer_get_team_box_score

Fetches the team box scores for Soccer games based on gender and seasons.

Parameters:

  • gender (str): Must be "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 for the specified seasons. The columns of the returned DataFrame are: team, goals_1, goals_2, goals_total, shots_1, shots_2, shots_total, saves_1, saves_2, saves_total, fouls_1, fouls_2, fouls_total, corners_1, corners_2, corners_total, game_date, game_id, goals_ot, goals_2ot, shots_ot, shots_2ot, saves_ot, saves_2ot, fouls_ot, fouls_2ot, corners_ot, corners_2ot, season, and season_type.

Example:

from usportspy import soccer_get_team_box_score

# Get team box scores for male Soccer for the 2019 and 2021 seasons
team_box_scores_male = soccer_get_team_box_score("m", [2019, 2021])
print(team_box_scores_male.head())

# Get team box scores for female Soccer for the 2019 and 2021 seasons
team_box_scores_female = soccer_get_team_box_score("w", [2019, 2021])
print(team_box_scores_female.head())

Expected output:

           team  goals_1  goals_2  goals_total  shots_1  shots_2  shots_total  saves_1  saves_2  ...  shots_2ot  saves_ot  saves_2ot  fouls_ot  fouls_2ot  corners_ot  corners_2ot   season season_type
0  Ontario Tech        1      0.0            1        3      7.0           10        3      2.0  ...        NaN       NaN        NaN       NaN        NaN         NaN          NaN  2019-20           p
1       Queen's        0      0.0            0        4      3.0            7        2      4.0  ...        NaN       NaN        NaN       NaN        NaN         NaN          NaN  2019-20           p
2     Nipissing        0      0.0            0        3      4.0            7        1      4.0  ...        NaN       NaN        NaN       NaN        NaN         NaN          NaN  2019-20           p
3       Toronto        3      3.0            6        6      9.0           15        0      4.0  ...        NaN       NaN        NaN       NaN        NaN         NaN          NaN  2019-20           p
4      McMaster        2      0.0            3        4      2.0            8        1      1.0  ...        1.0       0.0        2.0       1.0        3.0         0.0          0.0  2019-20           p

[5 rows x 30 columns]


        team  goals_1  goals_2  goals_total  shots_1  shots_2  shots_total  saves_1  saves_2  ...  goals_2ot  shots_ot  shots_2ot  saves_ot saves_2ot  fouls_ot  fouls_2ot   season  season_type
0      Brock        0      0.0            0        3      4.0            7        5      1.0  ...        NaN       NaN        NaN       NaN       NaN       NaN        NaN  2019-20            p
1   McMaster        0      1.0            1       13      6.0           19        0      1.0  ...        NaN       NaN        NaN       NaN       NaN       NaN        NaN  2019-20            p
2  Nipissing        0      0.0            0        3      4.0            9        3      2.0  ...        0.0       1.0        1.0       4.0       0.0       2.0        0.0  2019-20            p
3    Ryerson        0      0.0            0        4      3.0           11        1      3.0  ...        0.0       4.0        0.0       1.0       0.0       2.0        2.0  2019-20            p
4   Waterloo        0      0.0            0        3      7.0           10        5      2.0  ...        NaN       NaN        NaN       NaN       NaN       NaN        NaN  2019-20            p

[5 rows x 24 columns]

soccer_get_player_box_score

Fetches the player box scores for Soccer games based on gender and seasons.

Parameters:

  • gender (str): Must be "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 for the specified seasons. The columns of the returned DataFrame are: player, sh, sog, g, a, min, yellow_card, red_card, player_links, game_id, sog_against, ga, sv, game_date, season, and season_type.

Example:

from usportspy import soccer_get_player_box_score

# Get player box scores for male Soccer for the 2019 and 2021 seasons
player_box_scores_male = soccer_get_player_box_score("m", [2019, 2021])
print(player_box_scores_male.head())

# Get player box scores for female Soccer for the 2019 and 2021 seasons
player_box_scores_female = soccer_get_player_box_score("w", [2019, 2021])
print(player_box_scores_female.head())

Expected output:

            player  sh  sog  g  a  min  yellow_card  red_card                                       player_links        game_id  sog_against   ga   sv game_date   season season_type
0   Adrian Butters   0    0  0  0    0            0         0  /sports/msoc/2019-20p/boxscores/20191023_rxx2....  20191023_rxx2          NaN  NaN  NaN       NaN  2019-20           p
1       Alex Jones   0    0  0  0   90            0         0  /sports/msoc/2019-20p/boxscores/20191023_rxx2....  20191023_rxx2          5.0  1.0  4.0       NaN  2019-20           p
2    Braeden Levac   0    0  0  0   14            0         0  /sports/msoc/2019-20p/boxscores/20191023_rxx2....  20191023_rxx2          NaN  NaN  NaN       NaN  2019-20           p
3  Cameron Wallace   0    0  0  0   69            0         0  /sports/msoc/2019-20p/boxscores/20191023_rxx2....  20191023_rxx2          NaN  NaN  NaN       NaN  2019-20           p
4        Hyung lee   2    1  0  0   31            1         0  /sports/msoc/2019-20p/boxscores/20191023_rxx2....  20191023_rxx2          NaN  NaN  NaN       NaN  2019-20           p


             player  sh  sog  g  a  min  yellow_card  red_card                                       player_links        game_id  sog_against  ga  sv game_date  ds   season season_type
0   Adriana Kanisek   0    0  0  0    0            0         0  /sports/wsoc/2019-20p/boxscores/20191023_6zqn....  20191023_6zqn          NaN NaN NaN       NaN NaN  2019-20           p
1    Ally Riganelli   0    0  0  0    0            0         0  /sports/wsoc/2019-20p/boxscores/20191023_6zqn....  20191023_6zqn          NaN NaN NaN       NaN NaN  2019-20           p
2        Amy Froome   1    0  0  0    0            0         0  /sports/wsoc/2019-20p/boxscores/20191023_6zqn....  20191023_6zqn          NaN NaN NaN       NaN NaN  2019-20           p
3  Cassandra Stirpe   1    0  0  0    0            0         0  /sports/wsoc/2019-20p/boxscores/20191023_6zqn....  20191023_6zqn          NaN NaN NaN       NaN NaN  2019-20           p
4     Ivana Kanisek   2    0  0  0    0            0         0  /sports/wsoc/2019-20p/boxscores/20191023_6zqn....  20191023_6zqn          NaN NaN NaN       NaN NaN  2019-20           p

soccer_get_pbp

Fetches the play-by-play (PBP) data for Soccer games based on gender and seasons.

Parameters:

  • gender (str): Must be "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 for the specified seasons. The columns of the returned DataFrame are: time, event, game_id, away, home, season, and season_type.

Example:

from usportspy import soccer_get_pbp

# Get play-by-play data for male Soccer for the 2019 and 2021 seasons
pbp_male = soccer_get_pbp("m", [2019, 2021])
print(pbp_male.head())

# Get play-by-play data for female Soccer for the 2019 and 2021 seasons
pbp_female = soccer_get_pbp("w", [2019, 2021])
print(pbp_female.head())

Expected output:

    time                                          event        game_id     away          home   season season_type
0   0:00              Alex Jones at goalie for Queen's.  20191023_rxx2  Queen's  Ontario Tech  2019-20           p
1   0:00    Nicholas Miller at goalie for Ontario Tech.  20191023_rxx2  Queen's  Ontario Tech  2019-20           p
2    NaN                          Foul on Ontario Tech.  20191023_rxx2  Queen's  Ontario Tech  2019-20           p
3    NaN                               Foul on Queen's.  20191023_rxx2  Queen's  Ontario Tech  2019-20           p
4  11:59  Corner kick by Queen's Matthew Reale [11:59].  20191023_rxx2  Queen's  Ontario Tech  2019-20           p


   time                                           event        game_id     away       home   season season_type
0  0:00           Elisa Lapadula at goalie for Ryerson.  20191023_fos9  Ryerson  Nipissing  2019-20           p
1  0:00          Mykaela Volpe at goalie for Nipissing.  20191023_fos9  Ryerson  Nipissing  2019-20           p
2   NaN                              Foul on Nipissing.  20191023_fos9  Ryerson  Nipissing  2019-20           p
3  3:28  Corner kick by Nipissing Sarah Matesic [3:28].  20191023_fos9  Ryerson  Nipissing  2019-20           p
4  8:36                        Offside against Ryerson.  20191023_fos9  Ryerson  Nipissing  2019-20           p