Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -131,7 +131,7 @@ def seasonlong_build(data_sample):
|
|
131 |
return season_long_table
|
132 |
|
133 |
@st.cache_data(show_spinner=False)
|
134 |
-
def
|
135 |
cor_testing = data_sample
|
136 |
cor_testing = cor_testing[cor_testing['Season'] == '22023']
|
137 |
date_list = cor_testing['Date'].unique().tolist()
|
@@ -147,6 +147,23 @@ def run_corr(data_sample):
|
|
147 |
|
148 |
return corrM
|
149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
@st.cache_data(show_spinner=False)
|
151 |
def split_frame(input_df, rows):
|
152 |
df = [input_df.loc[i : i + rows - 1, :] for i in range(0, len(input_df), rows)]
|
@@ -259,6 +276,8 @@ with tab2:
|
|
259 |
total_players = indv_players.Player.values.tolist()
|
260 |
total_dates = gamelog_table.Date.values.tolist()
|
261 |
|
|
|
|
|
262 |
split_var1_t2 = st.radio("Would you like to view specific teams or specific players?", ('Specific Teams', 'Specific Players'), key='split_var1_t2')
|
263 |
|
264 |
if split_var1_t2 == 'Specific Teams':
|
@@ -284,20 +303,28 @@ with tab2:
|
|
284 |
with col2:
|
285 |
if split_var1_t2 == 'Specific Teams':
|
286 |
display = st.container()
|
|
|
287 |
gamelog_table = gamelog_table[gamelog_table['Date'] >= low_date_t2]
|
288 |
gamelog_table = gamelog_table[gamelog_table['Date'] <= high_date_t2]
|
289 |
gamelog_table = gamelog_table[gamelog_table['Min'] >= min_var1_t2[0]]
|
290 |
gamelog_table = gamelog_table[gamelog_table['Min'] <= min_var1_t2[1]]
|
291 |
gamelog_table = gamelog_table[gamelog_table['Team'].isin(corr_var1_t2)]
|
292 |
-
|
|
|
|
|
|
|
293 |
display.dataframe(corr_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), height=1000, use_container_width = True)
|
294 |
|
295 |
elif split_var1_t2 == 'Specific Players':
|
296 |
display = st.container()
|
|
|
297 |
gamelog_table = gamelog_table[gamelog_table['Date'] >= low_date_t2]
|
298 |
gamelog_table = gamelog_table[gamelog_table['Date'] <= high_date_t2]
|
299 |
gamelog_table = gamelog_table[gamelog_table['Min'] >= min_var1_t2[0]]
|
300 |
gamelog_table = gamelog_table[gamelog_table['Min'] <= min_var1_t2[1]]
|
301 |
gamelog_table = gamelog_table[gamelog_table['Player'].isin(corr_var1_t2)]
|
302 |
-
|
|
|
|
|
|
|
303 |
display.dataframe(corr_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
|
|
131 |
return season_long_table
|
132 |
|
133 |
@st.cache_data(show_spinner=False)
|
134 |
+
def run_fantasy_corr(data_sample):
|
135 |
cor_testing = data_sample
|
136 |
cor_testing = cor_testing[cor_testing['Season'] == '22023']
|
137 |
date_list = cor_testing['Date'].unique().tolist()
|
|
|
147 |
|
148 |
return corrM
|
149 |
|
150 |
+
@st.cache_data(show_spinner=False)
|
151 |
+
def run_min_corr(data_sample):
|
152 |
+
cor_testing = data_sample
|
153 |
+
cor_testing = cor_testing[cor_testing['Season'] == '22023']
|
154 |
+
date_list = cor_testing['Date'].unique().tolist()
|
155 |
+
player_list = cor_testing['Player'].unique().tolist()
|
156 |
+
corr_frame = pd.DataFrame()
|
157 |
+
corr_frame['DATE'] = date_list
|
158 |
+
for player in player_list:
|
159 |
+
player_testing = cor_testing[cor_testing['Player'] == player]
|
160 |
+
fantasy_map = dict(zip(player_testing['Date'], player_testing['Min']))
|
161 |
+
corr_frame[player] = corr_frame['DATE'].map(fantasy_map)
|
162 |
+
players_fantasy = corr_frame.drop('DATE', axis=1)
|
163 |
+
corrM = players_fantasy.corr()
|
164 |
+
|
165 |
+
return corrM
|
166 |
+
|
167 |
@st.cache_data(show_spinner=False)
|
168 |
def split_frame(input_df, rows):
|
169 |
df = [input_df.loc[i : i + rows - 1, :] for i in range(0, len(input_df), rows)]
|
|
|
276 |
total_players = indv_players.Player.values.tolist()
|
277 |
total_dates = gamelog_table.Date.values.tolist()
|
278 |
|
279 |
+
corr_var = st.radio("Are you correlating fantasy or minutes?", ('Fantasy', 'Minutes'), key='corr_var')
|
280 |
+
|
281 |
split_var1_t2 = st.radio("Would you like to view specific teams or specific players?", ('Specific Teams', 'Specific Players'), key='split_var1_t2')
|
282 |
|
283 |
if split_var1_t2 == 'Specific Teams':
|
|
|
303 |
with col2:
|
304 |
if split_var1_t2 == 'Specific Teams':
|
305 |
display = st.container()
|
306 |
+
gamelog_table = gamelog_table.sort_values(by='Fantasy', ascending=False)
|
307 |
gamelog_table = gamelog_table[gamelog_table['Date'] >= low_date_t2]
|
308 |
gamelog_table = gamelog_table[gamelog_table['Date'] <= high_date_t2]
|
309 |
gamelog_table = gamelog_table[gamelog_table['Min'] >= min_var1_t2[0]]
|
310 |
gamelog_table = gamelog_table[gamelog_table['Min'] <= min_var1_t2[1]]
|
311 |
gamelog_table = gamelog_table[gamelog_table['Team'].isin(corr_var1_t2)]
|
312 |
+
if corr_var == 'Fantasy':
|
313 |
+
corr_display = run_fantasy_corr(gamelog_table)
|
314 |
+
elif corr_var == 'Minutes':
|
315 |
+
corr_display = run_min_corr(gamelog_table)
|
316 |
display.dataframe(corr_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), height=1000, use_container_width = True)
|
317 |
|
318 |
elif split_var1_t2 == 'Specific Players':
|
319 |
display = st.container()
|
320 |
+
gamelog_table = gamelog_table.sort_values(by='Fantasy', ascending=False)
|
321 |
gamelog_table = gamelog_table[gamelog_table['Date'] >= low_date_t2]
|
322 |
gamelog_table = gamelog_table[gamelog_table['Date'] <= high_date_t2]
|
323 |
gamelog_table = gamelog_table[gamelog_table['Min'] >= min_var1_t2[0]]
|
324 |
gamelog_table = gamelog_table[gamelog_table['Min'] <= min_var1_t2[1]]
|
325 |
gamelog_table = gamelog_table[gamelog_table['Player'].isin(corr_var1_t2)]
|
326 |
+
if corr_var == 'Fantasy':
|
327 |
+
corr_display = run_fantasy_corr(gamelog_table)
|
328 |
+
elif corr_var == 'Minutes':
|
329 |
+
corr_display = run_min_corr(gamelog_table)
|
330 |
display.dataframe(corr_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|