def getTotalAve(lis, GTBP): df = pd.DataFrame() for x in range(len(lis)): df = df.append(pfp.PlayerFantasyProfile(lis[x]).get_data_frames()[0], ignore_index=True) Time.sleep(delay) df = df.drop(columns=['GROUP_SET', 'GROUP_VALUE', 'W', 'L', 'W_PCT', 'MIN', 'OREB', 'DREB', 'BLKA', 'PF', 'PFD', 'PLUS_MINUS', 'DD2', 'TD3', 'FAN_DUEL_PTS', 'NBA_FANTASY_PTS', 'FG3A', 'FG3_PCT', 'FG_PCT', 'FT_PCT' ]) df.insert(1, 'FGMPG', df.FGM / df.GP) df.insert(2, 'FGAPG', df.FGA / df.GP) df.insert(3, 'FTMPG', df.FTM / df.GP) df.insert(4, 'FTAPG', df.FTA / df.GP) df.insert(7, '3PTMPG', df.FG3M / df.GP) df.insert(9, 'PPG', df.PTS / df.GP) df.insert(10, 'RPG', df.REB / df.GP) df.insert(11, 'APG', df.AST / df.GP) df.insert(16, 'TOPG', df.TOV / df.GP) df.insert(13, 'SPG', df.STL / df.GP) df.insert(15, 'BPG', df.BLK / df.GP) df.insert(0, 'GTBP', GTBP) df = df.drop(columns=['PTS', 'AST', 'REB', 'BLK', 'STL', 'TOV', 'FGA', 'FG3M', 'GP', 'FTA', 'FTM', 'FGM' ]) return df
def main(): df_final = pd.DataFrame() df_opponent = pd.DataFrame() for x in range(len(lis)): df_final = df_final.append(cleanse(pfp.PlayerFantasyProfile(lis[x]).get_data_frames()[0]), ignore_index=True) time.sleep(.5) print('My lineup stas: ') print('') print(df_final) print('') df_final = cleanseSomeMore(df_final) print('This is my total stats:') print('') print(df_final) print('') if len(lis2): for x in range(len(lis2)): df_opponent = df_opponent.append(cleanse(pfp.PlayerFantasyProfile(lis2[x]).get_data_frames()[0]), ignore_index=True) print('My Opponent\'s lineup stas: ') print('') print(df_opponent) print('') df_opponent = cleanseSomeMore(df_opponent) print('This is my opponent\'s total stats:') print('') print(df_opponent) print('')
def main(): df_final = pd.DataFrame() df_opponent = pd.DataFrame() for x in range(len(lis)): df_final = df_final.append(cleanse( pfp.PlayerFantasyProfile(lis[x]).get_data_frames()[0]), ignore_index=True) for x in range(len(lis2)): df_opponent = df_opponent.append(cleanse( pfp.PlayerFantasyProfile(lis2[x]).get_data_frames()[0]), ignore_index=True) print(df_final) print(df_opponent) df_final = cleanseSomeMore(df_final) df_opponent = cleanseSomeMore(df_opponent) print(df_final) print(df_opponent)
def getFantasyProfileDict(self, mode="PerGame", type_season="Regular Season", id="201939", my_season="2018-19"): fantasy_obj = playerfantasyprofile.PlayerFantasyProfile( player_id=id, measure_type_base="Base", pace_adjust_no="N", per_mode36=mode, plus_minus_no="N", rank_no="N", season=my_season, season_type_playoffs=type_season, league_id_nullable="00") fantasy_dict = fantasy_obj.get_dict() with open('season_stats.json', 'w') as fp: json.dump(fantasy_dict, fp, indent=3) return fantasy_dict
from nba_api.stats.endpoints import commonplayerinfo, playerfantasyprofile from nba_api.stats.static import players import pandas playerName = 'Lebron James' seasonYear = '2015-16' statCategory = 'GROUP_VALUE' playerId = players.find_players_by_full_name(playerName)[0]['id'] print(playerId) player_info = commonplayerinfo.CommonPlayerInfo(player_id=playerId) playerInfo = player_info.common_player_info.get_data_frame() # print (avaliableSeasonDF.at[0, 'SEASON_ID']) print(playerInfo) # team_id = seasonInfo = playerfantasyprofile.PlayerFantasyProfile(player_id=playerId, season=seasonYear) seasonInfoByGame = seasonInfo.opponent.get_data_frame() print(seasonInfoByGame) statDF = seasonInfoByGame.loc[:, statCategory] print(statDF)