Spaces:
Build error
Build error
Update app.py
Browse files
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 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
season_long_table
|
| 77 |
-
season_long_table['
|
| 78 |
-
|
| 79 |
-
season_long_table['
|
| 80 |
-
season_long_table['
|
| 81 |
-
season_long_table['
|
| 82 |
-
|
| 83 |
-
season_long_table['
|
| 84 |
-
season_long_table['
|
| 85 |
-
season_long_table['
|
| 86 |
-
|
| 87 |
-
season_long_table['
|
| 88 |
-
season_long_table['
|
| 89 |
-
season_long_table['
|
| 90 |
-
|
| 91 |
-
season_long_table['
|
| 92 |
-
season_long_table['
|
| 93 |
-
season_long_table['
|
| 94 |
-
season_long_table['
|
| 95 |
-
season_long_table['
|
| 96 |
-
season_long_table['
|
| 97 |
-
season_long_table['
|
| 98 |
-
season_long_table['
|
| 99 |
-
season_long_table['
|
| 100 |
-
season_long_table['
|
| 101 |
-
season_long_table['
|
| 102 |
-
season_long_table['
|
| 103 |
-
season_long_table['
|
| 104 |
-
season_long_table['
|
| 105 |
-
season_long_table['
|
| 106 |
-
|
| 107 |
-
season_long_table['
|
| 108 |
-
|
| 109 |
-
season_long_table['
|
| 110 |
-
|
| 111 |
-
season_long_table['
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
season_long_table = season_long_table.drop_duplicates(subset='PLAYER_NAME')
|
| 114 |
|
| 115 |
-
return
|
| 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
|
| 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
|
| 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':
|