Ejemplo n.º 1
0
def getteamprofile(filter_season):
    gameids = goldsberry.GameIDs()
    gameids = pd.DataFrame(gameids)
    teamids = gameids['HOME_TEAM_ID'].ix[gameids['SEASON']
            ==filter_season].drop_duplicates()
    teamids_full = pd.DataFrame() # Create empty Data Frame
    for i in teamids.values:
            team = goldsberry.team.team_info(i)
            teamids_full = pd.concat([teamids_full,
                    pd.DataFrame(team.info())])
    return teamids_full
Ejemplo n.º 2
0
import goldsberry
import pandas as pd
import urllib


gameids = goldsberry.GameIDs()

print("game ids: {}".format(gameids))
print(gameids.game_list())

def get_player_img(player_id):
    """Returns the image of the player from stats.nba.com

    Parameters
    ----------
    player_id: int
        The player ID used to find the image.
    """
    url = "http://stats.nba.com/media/players/230x185/"+str(player_id)+".png"
    img_file = str(player_id) + ".png"
    # img = plt.imread(urllib.urlretrieve(url, img_file)[0])
    # return plt.imshow(img)
    print ("img file: {}".format(url))
Ejemplo n.º 3
0
import pandas as pd
import numpy as np

westTeams = [['Golden State Warriors', 1610612744],
             ['San Antonio Spurs', 1610612759],
             ['Oklahoma City Thunder', 1610612760],
             ['Los Angeles Clippers', 1610612746],
             ['Memphis Grizzlies', 1610612763],
             ['Portland Trailblazers', 1610612757],
             ['Dallas Mavericks', 1610612742], ['Houston Rockets', 1610612745]]
eastTeams = [['Cleveland Cavaliers', 1610612739],
             ['Toronto Raptors', 1610612761], ['Atlanta Hawks', 1610612737],
             ['Boston Celtics', 1610612738], ['Miami Heat', 1610612748],
             ['Charlotte Hornets', 1610612766],
             ['Detroit Pistons', 1610612765], ['Indiana Pacers', 1610612754]]
gameids = gb.GameIDs()
players = gb.PlayerList()
gameids2015 = pd.DataFrame(gameids.game_list())
gameids2015.to_csv('AllTeams.csv')
players2015 = pd.DataFrame(players.players())

for i in range(0, 4):
    team1WestName = westTeams[i][0]
    team1WestID = westTeams[i][1]
    team1WestPlayers = players2015[players2015['TEAM_ID'] == team1WestID]
    team1WestLog = gameids2015[gameids2015['TEAM_ID'] == team1WestID]

    team1WestPlayerID = team1WestPlayers['PERSON_ID']
    team1WestPlayerGameLog = []
    for personID in team1WestPlayerID:
        team1WestPlayerGameLog.append(
Ejemplo n.º 4
0
 def get_games():
     games_json = goldsberry.GameIDs()
     df_games = pd.DataFrame(games_json.game_list())
     df_games.sort_values('GAME_ID', inplace=True)
     df_games.reset_index(drop=True, inplace=True)
     return df_games
Ejemplo n.º 5
0
def pre_post_ASB_2017_18(playercode):
    first, last = playercode.split('_')
    first = first.title()
    last = last.title()

    players = goldsberry.PlayerList(Season='2017-18')
    players2017 = pd.DataFrame(players.players())

    games = goldsberry.GameIDs()
    games.get_new_data(Season='2017-18')
    games2017 = pd.DataFrame(games.game_list())

    player_id = players2017.loc[players2017['PLAYERCODE'] ==
                                playercode]['PERSON_ID']

    team_id = players2017.loc[players2017['PLAYERCODE'] ==
                              playercode]['TEAM_ID']

    player_game_logs = goldsberry.player.game_logs(player_id)
    player_game_logs_2017 = pd.DataFrame(player_game_logs.logs())
    player_game_logs_2017['GmSc'] = player_game_logs_2017.apply(
        lambda row: gamescore(row), axis=1)
    player_game_logs_2017['TSP'] = player_game_logs_2017.apply(
        lambda row: TSPercent(row), axis=1)
    post_all_star = player_game_logs_2017.loc[58:82]
    pre_all_star = player_game_logs_2017.loc[0:57]
    # lgl17 = post_all_star.loc[
    #								(post_all_star['PTS'] > 25)
    #								& (post_all_star['PTS'] < 30)
    #								]

    print getGameLog(player_game_logs_2017.loc[5], playercode, players2017,
                     games2017)

    sortedAfter = post_all_star.sort_values(by=['TSP'])
    sortedBefore = pre_all_star.sort_values(by=['TSP'])

    afterGS = np.array(pd.DataFrame(sortedAfter, columns=['GmSc']))
    afterTSP = np.array(pd.DataFrame(sortedAfter, columns=['TSP']))

    beforeGS = np.array(pd.DataFrame(sortedBefore, columns=['GmSc']))
    beforeTSP = np.array(pd.DataFrame(sortedBefore, columns=['TSP']))
    print afterGS.mean()
    print "\n"
    print beforeGS.mean()

    # MAKE A LINE PLOT
    # #######################

    # USE FOR A BASIC LINE PLOT
    # scaled_post = (pd.Series(range(1,len(after) + 1)) * len(before)/len(after)).tolist()
    # print afterTSP
    # print afterGS

    # plt.plot(afterTSP,afterGS,beforeTSP,beforeGS)
    # plt.xlabel('True Shooting %')
    # plt.ylabel('GameScore')

    # # MAKE A BOX/WHISKER
    # #######################

    # fig, axs = plt.subplots(1,2)

    # axs[0].boxplot(before)
    # axs[0].set_title("Before All-Star Break (PPG)")

    # axs[1].boxplot(after)
    # axs[1].set_title("After All-Star Break (PPG)")
    # axs[1].set_ylim(axs[0].get_ylim())

    # fig.subplots_adjust(left=0.08, right=0.98, bottom=0.05, top=0.9, hspace =0.4, wspace=0.3)

    # MAKE A HISTOGRAM
    # #####################

    fig, axs = plt.subplots(1, 2, sharey=True, tight_layout=True)

    axs[0].hist(beforeGS, bins=15)
    axs[0].set_title('GameScore Before All-Star Break')
    axs[1].hist(afterGS, bins=15)
    axs[1].set_title('GameScore After All-Star Break')

    plt.savefig('figure.png')
Ejemplo n.º 6
0
def getgameid():
    gameids = goldsberry.GameIDs()
    gameids = pd.DataFrame(gameids)
    return gameids