def team_stats_adv(team, year): writer = ExcelWriter("%s-%d_AdvancedStats.xlsx" % (team, year)) team_df = get_team_misc(team, year) team_df.to_excel(writer, sheet_name=team, startrow=0, startcol=0, index=False, header=True) writer.save()
def team_misc(team, year): print("Saving into excel sheet... ") writer = ExcelWriter("./Excel-Sheets/%s-%d_MISC_Stats.xlsx" % (team, year)) roster_stats_df = get_team_misc(team, year).reset_index().transpose() roster_stats_df.to_excel(writer, sheet_name=team, startrow=0, startcol=0, index=False, header=True) writer.save()
def test_get_team_misc(self): series = get_team_misc('GSW', 2019) expected_indices = [ 'AGE', 'W', 'L', 'PW', 'PL', 'MOV', 'SOS', 'SRS', 'ORtg', 'DRtg', 'NRtg', 'PACE', 'FTr', '3PAr', 'TS%', 'eFG%', 'TOV%', 'ORB%', 'FT/FGA', 'eFG%', 'TOV%', 'DRB%', 'FT/FGA', 'ARENA', 'ATTENDANCE', 'ATTENDANCE/G', 'TEAM', 'SEASON' ] self.assertCountEqual(list(series.index), expected_indices) series = get_team_misc('CHO', 2019) self.assertCountEqual(list(series.index), expected_indices) series = get_team_misc('NOK', 2007) self.assertCountEqual(list(series.index), expected_indices) series = get_team_misc('TCB', 1951) self.assertCountEqual(list(series.index), expected_indices)
def test_get_team_misc(self): series = get_team_misc('GSW', 2019) expected_indices = [ 'W', 'L', 'PW', 'PL', 'MOV', 'SOS', 'SRS', 'ORtg', 'DRtg', 'Pace', 'FTr', '3PAr', 'eFG%', 'TOV%', 'ORB%', 'FT/FGA', 'eFG%', 'TOV%', 'DRB%', 'FT/FGA', 'Arena', 'Attendance' ] self.assertListEqual(list(series.index), expected_indices)
def user_input(): team_or_player = input("What stats would you like to see: (1)Team or (2)Player ") if team_or_player == '1': user_team = input("What team would you like to view? ") user_season = int(input("Enter the desired season: ")) user_stats = input("Enter the number for what stat you would like to see: \n1.) Roster List\n" "2.) Team Stats\n" "3.) Team Opponent Stats\n" "4.) Roster Stats\n" "5.) Misc Stats\n") print_or_excel = input("Would you like to save information in an excel sheet (Y/N)? ").upper() if user_stats == '1': if print_or_excel == 'Y': roster_list(user_team, user_season) print("Saved") elif print_or_excel == 'N': print(get_roster(user_team, user_season)) elif user_stats == '2': data_format = input("Enter data format: (TOTAL | PER_GAME): ").upper() if print_or_excel == 'Y': team_stats(user_team, user_season, data_format) print(get_team_stats(user_team, user_season, data_format)) elif print_or_excel == 'N': print(get_team_stats(user_team, user_season, data_format)) elif user_stats == '3': data_format = input("Enter data format: (TOTAL | PER_GAME: ").upper() if print_or_excel == 'Y': team_opp_stats(user_team, user_season, data_format) print(get_opp_stats(user_team, user_season, data_format)) elif print_or_excel == 'N' or 'n': print(get_opp_stats(user_team, user_season, data_format)) elif user_stats == '4': user_playoffs = input("Would you like playoff roster stats? (Y/N) ") data_format = input("Enter data format: (TOTAL | PER_GAME): ").upper() playoffs = False if user_playoffs == 'Y': playoffs = True if print_or_excel == 'Y': roster_stats(user_team, user_season, data_format, playoffs) print(get_roster_stats(user_team, user_season, data_format, playoffs)) elif print_or_excel == 'N': print(get_roster_stats(user_team, user_season, data_format, playoffs)) elif user_stats == '5': if print_or_excel == 'Y': team_misc(user_team, user_season) print(get_team_misc(user_team, user_season)) elif print_or_excel == 'N': print(get_team_misc(user_team, user_season)) elif team_or_player == '2': user_player = input('What player do you like to view? ') print_or_excel = input("Save into excel sheet? (Y/N): ").upper() user_stats = input("Enter the number for what stat you would like to see: \n" "1.) Player Stats\n" "2.) Game Logs\n") user_playoffs = input("Playoff Stats? (Y/N): ").upper() if user_stats == '1': stat_type = input("Enter stat type: (PER_GAME | PER_MINUTE | PER_POSS | ADVANCED): ").upper() user_career = input("Career Stats? (Y/N): ").upper() if user_playoffs == 'Y': playoffs = True else: playoffs = False if user_career == 'Y': career = True else: career = False if print_or_excel == "Y": player_stats(user_player, stat_type, playoffs, career) print(get_stats(user_player, stat_type, playoffs, career)) elif print_or_excel == "N": print(get_stats(user_player, stat_type, playoffs, career)) elif user_stats == '2': user_start_date = input("Enter start date: (YYYY-MM-DD): ").upper() user_end_date = input("Enter end date: (YYYY-MM-DD): ") if user_playoffs == 'Y': playoffs = True else: playoffs = False if print_or_excel == "Y": player_game_logs(user_player, user_start_date, user_end_date, playoffs) print(get_game_logs(user_player, user_start_date, user_end_date, playoffs)) elif print_or_excel == "N": print(get_game_logs(user_player, user_start_date, user_end_date, playoffs))
from basketball_reference_scraper.teams import get_roster, get_team_stats, get_opp_stats, get_roster_stats, get_team_misc df = get_roster('GSW', 2019) print(df) s = get_team_stats('GSW', 2019, data_format='PER_GAME') print(s) s = get_opp_stats('GSW', 2019, data_format='PER_GAME') print(s) s = get_roster_stats('GSW', 2019, data_format='PER_GAME', playoffs=False) print(s) s = get_team_misc('GSW', 2019) print(s) from basketball_reference_scraper.players import get_stats, get_game_logs s = get_stats('Stephen Curry', stat_type='PER_GAME', playoffs=False, career=False) print(s) df = get_game_logs('LeBron James', '2010-01-19', '2014-01-20', playoffs=False) print(df) from basketball_reference_scraper.seasons import get_schedule, get_standings s = get_schedule(2018, playoffs=False)
def getTeamMisc(year): atl = get_team_misc('ATL', year).to_frame().transpose() brk = get_team_misc('BRK', year).to_frame().transpose() bos = get_team_misc('BOS', year).to_frame().transpose() cho = get_team_misc('CHO', year).to_frame().transpose() chi = get_team_misc('CHI', year).to_frame().transpose() cle = get_team_misc('CLE', year).to_frame().transpose() dal = get_team_misc('DAL', year).to_frame().transpose() den = get_team_misc('DEN', year).to_frame().transpose() det = get_team_misc('DET', year).to_frame().transpose() gsw = get_team_misc('GSW', year).to_frame().transpose() hou = get_team_misc('HOU', year).to_frame().transpose() ind = get_team_misc('IND', year).to_frame().transpose() lac = get_team_misc('LAC', year).to_frame().transpose() lal = get_team_misc('LAL', year).to_frame().transpose() mem = get_team_misc('MEM', year).to_frame().transpose() mia = get_team_misc('MIA', year).to_frame().transpose() mil = get_team_misc('MIL', year).to_frame().transpose() mint = get_team_misc('MIN', year).to_frame().transpose() nop = get_team_misc('NOP', year).to_frame().transpose() nyk = get_team_misc('NYK', year).to_frame().transpose() okc = get_team_misc('OKC', year).to_frame().transpose() orl = get_team_misc('ORL', year).to_frame().transpose() phi = get_team_misc('PHI', year).to_frame().transpose() pho = get_team_misc('PHO', year).to_frame().transpose() por = get_team_misc('POR', year).to_frame().transpose() sac = get_team_misc('SAC', year).to_frame().transpose() sas = get_team_misc('SAS', year).to_frame().transpose() tor = get_team_misc('TOR', year).to_frame().transpose() uta = get_team_misc('UTA', year).to_frame().transpose() was = get_team_misc('WAS', year).to_frame().transpose() frames = [ atl, brk, bos, cho, chi, cle, dal, den, det, gsw, hou, ind, lac, lal, mem, mia, mil, mint, nop, nyk, okc, orl, phi, pho, por, sac, sas, tor, uta, was ] return pd.concat(frames)