<jupyter_start><jupyter_text>Get every player stats for a given season<jupyter_code>import goldsberry
import pandas as pd
import os.path
import csv
from goldsberry.team import *
pd.set_option("display.max_columns",50) # Change Pandas Display Options
goldsberry.__version__<jupyter_output><empty_output><jupyter_text>Define method that writes data into a csv<jupyter_code>def write_player_game_log_csv(team_file, player_game_logs):    
    with open(team_file, 'w') as csvfile:
        fieldnames = ['AST','BLK','DREB','FG3A','FG3M','FG3_PCT','FGA','FGM', 'FG_PCT',
                      'FTA', 'FTM', 'FT_PCT', 'GAME_DATE', 'Game_ID', 'LEAGUE_ID', 'MATCHUP', 'MIN', 'OREB', 
                      'PF', 'PLUS_MINUS', 'PLAYER_ID', 'PTS', 'REB', 'SEASON_ID', 'STL',
                      'WL','TOV']
        writer = csv.DictWriter(csvfile, fieldnames=fieldnames)

        writer.writeheader()        
        for team_row in player_game_logs.logs():
            writer.writerow({'AST' : team_row['AST'],
                              'BLK' : team_row['BLK'],
                              'DREB' : team_row['DREB'],
                              'FG3A' : team_row['FG3A'],
                              'FG3M' : team_row['FG3M'],
                              'FG3_PCT' : team_row['FG3_PCT'],
                              'FGA' : team_row['FGA'],
                              'FGM' : team_row['FGM'],
                              'FG_PCT' : team_row['FG_PCT'],
                              'FTA' : team_row['FTA'],
                              'FTM' : team_row['FTM'],
                              'FT_PCT' : team_row['FT_PCT'],
                              'GAME_DATE' : team_row['GAME_DATE'],
                              'Game_ID' : team_row['Game_ID'],
                              'MATCHUP' : team_row['MATCHUP'],
                              'MIN' : team_row['MIN'],
                              'OREB' : team_row['OREB'],
                              'PF' : team_row['PF'],
                              'PLUS_MINUS' : team_row['PLUS_MINUS'],
                              'PTS' : team_row['PTS'],
                              'PLAYER_ID' : team_row['Player_ID'],
                              'REB' : team_row['REB'],
                              'SEASON_ID' : team_row['SEASON_ID'],
                              'STL' : team_row['STL'],
                              'TOV' : team_row['TOV'],
                              'WL': team_row['WL']})<jupyter_output><empty_output><jupyter_text>Get player list and game logs for each player<jupyter_code>def get_player_stats(season='2015'):
    player_list = goldsberry.PlayerList()
    
    for player in player_list.players():
        player_name = player['PLAYERCODE']
        if player_name != None:
            csv_name = "%s_%s.csv" %(season, player_name)
            player_code = player['PERSON_ID']
            print csv_name, os.path.isfile(csv_name)

            if (os.path.isfile(csv_name) == False):
                player_game_logs = goldsberry.player.game_logs(player_code)
                write_player_game_log_csv(player_csv, player_game_logs)
get_player_stats()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13129722921914358, 'fraction_numerical': 0.004722921914357683, 'mean_word_length': 1.6497080900750625, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '110309', 'license': 'Apache-2.0', 'n_tokens_mistral': 1025, 'n_tokens_neox': 983, 'n_words': 157, 'path': 'py-Goldsberry/docs/GetPlayerStatsPerGame.ipynb', 'repo_name': 'LiuHao-THU/nba_logistic_regression', 'size': '3176'}