Multichem commited on
Commit
d9ad3e8
·
1 Parent(s): 6919d54

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -44
app.py CHANGED
@@ -69,50 +69,54 @@ def init_baselines():
69
  data_cols = gamelog_table.columns.drop(['PLAYER_NAME', 'TEAM_NAME', 'SEASON_ID', 'GAME_DATE', 'MATCHUP'])
70
  gamelog_table[data_cols] = gamelog_table[data_cols].apply(pd.to_numeric, errors='coerce')
71
 
72
- season_long_table = gamelog_table[['PLAYER_NAME', 'TEAM_NAME']]
73
- season_long_table['MIN'] = gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['MIN'].transform('mean').astype(float)
74
- season_long_table['touches'] = gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['touches'].transform('mean').astype(float)
75
- season_long_table['FGM'] = gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FGM'].transform('mean').astype(float)
76
- season_long_table['FGA'] = gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FGA'].transform('mean').astype(float)
77
- season_long_table['FG_PCT'] = (gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FGM'].transform('sum').astype(int) /
78
- gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FGA'].transform('sum').astype(int))
79
- season_long_table['FG3M'] = gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FG3M'].transform('mean').astype(float)
80
- season_long_table['FG3A'] = gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FG3A'].transform('mean').astype(float)
81
- season_long_table['FG3_PCT'] = (gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FG3M'].transform('sum').astype(int) /
82
- gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FG3A'].transform('sum').astype(int))
83
- season_long_table['FTM'] = gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FTM'].transform('mean').astype(float)
84
- season_long_table['FTA'] = gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FTA'].transform('mean').astype(float)
85
- season_long_table['FT_PCT'] = (gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FTM'].transform('sum').astype(int) /
86
- gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FTA'].transform('sum').astype(int))
87
- season_long_table['reboundChancesOffensive'] = gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['reboundChancesOffensive'].transform('mean').astype(float)
88
- season_long_table['OREB'] = gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['OREB'].transform('mean').astype(float)
89
- season_long_table['reboundChancesDefensive'] = gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['reboundChancesDefensive'].transform('mean').astype(float)
90
- season_long_table['DREB'] = gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['DREB'].transform('mean').astype(float)
91
- season_long_table['reboundChancesTotal'] = gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['reboundChancesTotal'].transform('mean').astype(float)
92
- season_long_table['REB'] = gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['REB'].transform('mean').astype(float)
93
- season_long_table['passes'] = gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['passes'].transform('mean').astype(float)
94
- season_long_table['secondaryAssists'] = gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['secondaryAssists'].transform('mean').astype(float)
95
- season_long_table['freeThrowAssists'] = gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['freeThrowAssists'].transform('mean').astype(float)
96
- season_long_table['assists'] = gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['assists'].transform('mean').astype(float)
97
- season_long_table['STL'] = gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['STL'].transform('mean').astype(float)
98
- season_long_table['BLK'] = gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['BLK'].transform('mean').astype(float)
99
- season_long_table['TOV'] = gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['TOV'].transform('mean').astype(float)
100
- season_long_table['PF'] = gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['PF'].transform('mean').astype(float)
101
- season_long_table['DD'] = gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['DD'].transform('mean').astype(float)
102
- season_long_table['TD'] = gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['TD'].transform('mean').astype(float)
103
- season_long_table['Fantasy'] = gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['Fantasy'].transform('mean').astype(float)
104
- season_long_table['FD_Fantasy'] = gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FD_Fantasy'].transform('mean').astype(float)
105
- season_long_table['rebound%'] = (gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['REB'].transform('sum').astype(int) /
106
- gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['reboundChancesTotal'].transform('sum').astype(int))
107
- season_long_table['assists_per_pass'] = (gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['assists'].transform('sum').astype(int) /
108
- gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['passes'].transform('sum').astype(int))
109
- season_long_table['Fantasy_per_touch'] = (gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['Fantasy'].transform('sum').astype(int) /
110
- gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['touches'].transform('sum').astype(int))
111
- season_long_table['FD_Fantasy_per_touch'] = (gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FD_Fantasy'].transform('sum').astype(int) /
112
- gamelog_table.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['touches'].transform('sum').astype(int))
 
 
 
 
113
  season_long_table = season_long_table.drop_duplicates(subset='PLAYER_NAME')
114
 
115
- return gamelog_table, season_long_table
116
 
117
  @st.cache_data(show_spinner=False)
118
  def split_frame(input_df, rows):
@@ -122,18 +126,19 @@ def split_frame(input_df, rows):
122
  def convert_df_to_csv(df):
123
  return df.to_csv().encode('utf-8')
124
 
125
- gamelog_table, season_long_table = init_baselines()
126
 
127
  col1, col2 = st.columns([1, 9])
128
  with col1:
129
  if st.button("Reset Data", key='reset1'):
130
  st.cache_data.clear()
131
- gamelog_table, season_long_table = init_baselines()
132
  split_var1 = st.radio("What table would you like to view?", ('Season Logs', 'Gamelogs'), key='split_var1')
133
 
134
  with col2:
135
  if split_var1 == 'Season Logs':
136
  display = st.container()
 
137
  display.dataframe(season_long_table.style.format(precision=2), use_container_width = True)
138
 
139
  elif split_var1 == 'Gamelogs':
 
69
  data_cols = gamelog_table.columns.drop(['PLAYER_NAME', 'TEAM_NAME', 'SEASON_ID', 'GAME_DATE', 'MATCHUP'])
70
  gamelog_table[data_cols] = gamelog_table[data_cols].apply(pd.to_numeric, errors='coerce')
71
 
72
+ return gamelog_table
73
+
74
+ @st.cache_data(show_spinner=False)
75
+ def seasonlong_build(data_sample):
76
+ season_long_table = data_sample[['PLAYER_NAME', 'TEAM_NAME']]
77
+ season_long_table['MIN'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['MIN'].transform('mean').astype(float)
78
+ season_long_table['touches'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['touches'].transform('mean').astype(float)
79
+ season_long_table['FGM'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FGM'].transform('mean').astype(float)
80
+ season_long_table['FGA'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FGA'].transform('mean').astype(float)
81
+ season_long_table['FG_PCT'] = (data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FGM'].transform('sum').astype(int) /
82
+ data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FGA'].transform('sum').astype(int))
83
+ season_long_table['FG3M'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FG3M'].transform('mean').astype(float)
84
+ season_long_table['FG3A'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FG3A'].transform('mean').astype(float)
85
+ season_long_table['FG3_PCT'] = (data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FG3M'].transform('sum').astype(int) /
86
+ data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FG3A'].transform('sum').astype(int))
87
+ season_long_table['FTM'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FTM'].transform('mean').astype(float)
88
+ season_long_table['FTA'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FTA'].transform('mean').astype(float)
89
+ season_long_table['FT_PCT'] = (data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FTM'].transform('sum').astype(int) /
90
+ data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FTA'].transform('sum').astype(int))
91
+ season_long_table['reboundChancesOffensive'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['reboundChancesOffensive'].transform('mean').astype(float)
92
+ season_long_table['OREB'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['OREB'].transform('mean').astype(float)
93
+ season_long_table['reboundChancesDefensive'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['reboundChancesDefensive'].transform('mean').astype(float)
94
+ season_long_table['DREB'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['DREB'].transform('mean').astype(float)
95
+ season_long_table['reboundChancesTotal'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['reboundChancesTotal'].transform('mean').astype(float)
96
+ season_long_table['REB'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['REB'].transform('mean').astype(float)
97
+ season_long_table['passes'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['passes'].transform('mean').astype(float)
98
+ season_long_table['secondaryAssists'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['secondaryAssists'].transform('mean').astype(float)
99
+ season_long_table['freeThrowAssists'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['freeThrowAssists'].transform('mean').astype(float)
100
+ season_long_table['assists'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['assists'].transform('mean').astype(float)
101
+ season_long_table['STL'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['STL'].transform('mean').astype(float)
102
+ season_long_table['BLK'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['BLK'].transform('mean').astype(float)
103
+ season_long_table['TOV'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['TOV'].transform('mean').astype(float)
104
+ season_long_table['PF'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['PF'].transform('mean').astype(float)
105
+ season_long_table['DD'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['DD'].transform('mean').astype(float)
106
+ season_long_table['TD'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['TD'].transform('mean').astype(float)
107
+ season_long_table['Fantasy'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['Fantasy'].transform('mean').astype(float)
108
+ season_long_table['FD_Fantasy'] = data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FD_Fantasy'].transform('mean').astype(float)
109
+ season_long_table['rebound%'] = (data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['REB'].transform('sum').astype(int) /
110
+ data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['reboundChancesTotal'].transform('sum').astype(int))
111
+ season_long_table['assists_per_pass'] = (data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['assists'].transform('sum').astype(int) /
112
+ data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['passes'].transform('sum').astype(int))
113
+ season_long_table['Fantasy_per_touch'] = (data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['Fantasy'].transform('sum').astype(int) /
114
+ data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['touches'].transform('sum').astype(int))
115
+ season_long_table['FD_Fantasy_per_touch'] = (data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['FD_Fantasy'].transform('sum').astype(int) /
116
+ data_sample.groupby(['PLAYER_NAME', 'SEASON_ID'], sort=False)['touches'].transform('sum').astype(int))
117
  season_long_table = season_long_table.drop_duplicates(subset='PLAYER_NAME')
118
 
119
+ return season_long_table
120
 
121
  @st.cache_data(show_spinner=False)
122
  def split_frame(input_df, rows):
 
126
  def convert_df_to_csv(df):
127
  return df.to_csv().encode('utf-8')
128
 
129
+ gamelog_table = init_baselines()
130
 
131
  col1, col2 = st.columns([1, 9])
132
  with col1:
133
  if st.button("Reset Data", key='reset1'):
134
  st.cache_data.clear()
135
+ gamelog_table = init_baselines()
136
  split_var1 = st.radio("What table would you like to view?", ('Season Logs', 'Gamelogs'), key='split_var1')
137
 
138
  with col2:
139
  if split_var1 == 'Season Logs':
140
  display = st.container()
141
+ season_long_table = seasonlong_build(gamelog_table)
142
  display.dataframe(season_long_table.style.format(precision=2), use_container_width = True)
143
 
144
  elif split_var1 == 'Gamelogs':