Multichem commited on
Commit
1329302
1 Parent(s): 58c7208

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +324 -0
app.py ADDED
@@ -0,0 +1,324 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pulp
2
+ import numpy as np
3
+ import pandas as pd
4
+ import random
5
+ import sys
6
+ import openpyxl
7
+ import re
8
+ import time
9
+ import streamlit as st
10
+ import matplotlib
11
+ from matplotlib.colors import LinearSegmentedColormap
12
+ from st_aggrid import GridOptionsBuilder, AgGrid, GridUpdateMode, DataReturnMode
13
+ import json
14
+ import requests
15
+ import gspread
16
+ import plotly.figure_factory as ff
17
+
18
+ scope = ['https://www.googleapis.com/auth/spreadsheets',
19
+ "https://www.googleapis.com/auth/drive"]
20
+
21
+ credentials = {
22
+ "type": "service_account",
23
+ "project_id": "sheets-api-connect-378620",
24
+ "private_key_id": "1005124050c80d085e2c5b344345715978dd9cc9",
25
+ "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCtKa01beXwc88R\nnPZVQTNPVQuBnbwoOfc66gW3547ja/UEyIGAF112dt/VqHprRafkKGmlg55jqJNt\na4zceLKV+wTm7vBu7lDISTJfGzCf2TrxQYNqwMKE2LOjI69dBM8u4Dcb4k0wcp9v\ntW1ZzLVVuwTvmrg7JBHjiSaB+x5wxm/r3FOiJDXdlAgFlytzqgcyeZMJVKKBQHyJ\njEGg/1720A0numuOCt71w/2G0bDmijuj1e6tH32MwRWcvRNZ19K9ssyDz2S9p68s\nYDhIxX69OWxwScTIHLY6J2t8txf/XMivL/636fPlDADvBEVTdlT606n8CcKUVQeq\npUVdG+lfAgMBAAECggEAP38SUA7B69eTfRpo658ycOs3Amr0JW4H/bb1rNeAul0K\nZhwd/HnU4E07y81xQmey5kN5ZeNrD5EvqkZvSyMJHV0EEahZStwhjCfnDB/cxyix\nZ+kFhv4y9eK+kFpUAhBy5nX6T0O+2T6WvzAwbmbVsZ+X8kJyPuF9m8ldcPlD0sce\ntj8NwVq1ys52eosqs7zi2vjt+eMcaY393l4ls+vNq8Yf27cfyFw45W45CH/97/Nu\n5AmuzlCOAfFF+z4OC5g4rei4E/Qgpxa7/uom+BVfv9G0DIGW/tU6Sne0+37uoGKt\nW6DzhgtebUtoYkG7ZJ05BTXGp2lwgVcNRoPwnKJDxQKBgQDT5wYPUBDW+FHbvZSp\nd1m1UQuXyerqOTA9smFaM8sr/UraeH85DJPEIEk8qsntMBVMhvD3Pw8uIUeFNMYj\naLmZFObsL+WctepXrVo5NB6RtLB/jZYxiKMatMLUJIYtcKIp+2z/YtKiWcLnwotB\nWdCjVnPTxpkurmF2fWP/eewZ+wKBgQDRMtJg7etjvKyjYNQ5fARnCc+XsI3gkBe1\nX9oeXfhyfZFeBXWnZzN1ITgFHplDznmBdxAyYGiQdbbkdKQSghviUQ0igBvoDMYy\n1rWcy+a17Mj98uyNEfmb3X2cC6WpvOZaGHwg9+GY67BThwI3FqHIbyk6Ko09WlTX\nQpRQjMzU7QKBgAfi1iflu+q0LR+3a3vvFCiaToskmZiD7latd9AKk2ocsBd3Woy9\n+hXXecJHPOKV4oUJlJgvAZqe5HGBqEoTEK0wyPNLSQlO/9ypd+0fEnArwFHO7CMF\nycQprAKHJXM1eOOFFuZeQCaInqdPZy1UcV5Szla4UmUZWkk1m24blHzXAoGBAMcA\nyH4qdbxX9AYrC1dvsSRvgcnzytMvX05LU0uF6tzGtG0zVlub4ahvpEHCfNuy44UT\nxRWW/oFFaWjjyFxO5sWggpUqNuHEnRopg3QXx22SRRTGbN45li/+QAocTkgsiRh1\nqEcYZsO4mPCsQqAy6E2p6RcK+Xa+omxvSnVhq0x1AoGAKr8GdkCl4CF6rieLMAQ7\nLNBuuoYGaHoh8l5E2uOQpzwxVy/nMBcAv+2+KqHEzHryUv1owOi6pMLv7A9mTFoS\n18B0QRLuz5fSOsVnmldfC9fpUc6H8cH1SINZpzajqQA74bPwELJjnzrCnH79TnHG\nJuElxA33rFEjbgbzdyrE768=\n-----END PRIVATE KEY-----\n",
26
+ "client_email": "gspread-connection@sheets-api-connect-378620.iam.gserviceaccount.com",
27
+ "client_id": "106625872877651920064",
28
+ "auth_uri": "https://accounts.google.com/o/oauth2/auth",
29
+ "token_uri": "https://oauth2.googleapis.com/token",
30
+ "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
31
+ "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/gspread-connection%40sheets-api-connect-378620.iam.gserviceaccount.com"
32
+ }
33
+
34
+ gc = gspread.service_account_from_dict(credentials)
35
+
36
+ st.set_page_config(layout="wide")
37
+
38
+ roo_format = {'Top_finish': '{:.2%}','Top_5_finish': '{:.2%}', 'Top_10_finish': '{:.2%}',
39
+ '120+%': '{:.2%}','10x%': '{:.2%}','11x%': '{:.2%}','12x%': '{:.2%}','Own': '{:.2%}','LevX': '{:.2%}'}
40
+ stat_format = {'Win%': '{:.2%}'}
41
+
42
+ game_betting_model = 'https://docs.google.com/spreadsheets/d/1Yq0vGriWK-bS79e-bD6_u9pqrYE6Yrlbb_wEkmH-ot0/edit#gid=172632260'
43
+ props_overall = 'DK_NBA_Props'
44
+ player_overall = 'https://docs.google.com/spreadsheets/d/1Yq0vGriWK-bS79e-bD6_u9pqrYE6Yrlbb_wEkmH-ot0/edit#gid=172632260'
45
+ points_overall = 'DK_Points_Props'
46
+ assists_overall = 'DK_Assists_Props'
47
+ rebounds_overall = 'DK_Rebounds_Props'
48
+ pa_overall = 'DK_PA_Props'
49
+ pr_overall = 'DK_PR_Props'
50
+ pra_overall = 'DK_PRA_Props'
51
+
52
+ @st.cache_data
53
+ def create_player_props(URL):
54
+ sh = gc.open_by_url(URL)
55
+ worksheet = sh.get_worksheet(8)
56
+ load_display = pd.DataFrame(worksheet.get_all_records())
57
+ overall_data = load_display[['Name', 'Position', 'Team', '3P', 'Points', 'Rebounds', 'Assists', 'Steals', 'Blocks']]
58
+ overall_data.rename(columns={"Name": "player"}, inplace = True)
59
+ overall_data['Points + Rebounds'] = overall_data['Points'] + overall_data['Rebounds']
60
+ overall_data['Points + Assists'] = overall_data['Points'] + overall_data['Assists']
61
+ overall_data['Points + Rebounds + Assists'] = overall_data['Points'] + overall_data['Rebounds'] + overall_data['Assists']
62
+
63
+ return overall_data
64
+
65
+ @st.cache_data
66
+ def load_game_betting(URL):
67
+ sh = gc.open_by_url(URL)
68
+ worksheet = sh.get_worksheet(1)
69
+ raw_display = pd.DataFrame(worksheet.get_all_records())
70
+
71
+ return raw_display
72
+
73
+ @st.cache_data
74
+ def load_props(URL):
75
+ sh = gc.open(URL)
76
+ worksheet = sh.get_worksheet(0)
77
+ raw_display = pd.DataFrame(worksheet.get_all_records())
78
+ raw_display.rename(columns={"player": "Player"}, inplace = True)
79
+
80
+ return raw_display
81
+
82
+ @st.cache_data
83
+ def load_player_baselines(URL):
84
+ sh = gc.open(URL)
85
+ worksheet = sh.get_worksheet(0)
86
+ raw_display = pd.DataFrame(worksheet.get_all_records())
87
+
88
+ return raw_display
89
+
90
+ @st.cache_data
91
+ def load_stat_specific(URL):
92
+ sh = gc.open(URL)
93
+ worksheet = sh.get_worksheet(0)
94
+ raw_display = pd.DataFrame(worksheet.get_all_records())
95
+ raw_display.rename(columns={"player": "Player"}, inplace = True)
96
+ raw_display = raw_display.drop(columns=['Model Probability', 'short%', 'mid%', 'long%', 's_weighted%', 'm_weighted%', 'l_weighted%', 'weighted prob%'])
97
+
98
+ return raw_display
99
+
100
+ team_frame = load_game_betting(game_betting_model)
101
+ props_frame = create_player_props(player_overall)
102
+
103
+ tab1, tab2, tab3, tab4 = st.tabs(["Game Betting Model", "Player Prop Baselines", "Stat Specific Props Projections", "Player Prop Simulations"])
104
+
105
+ def convert_df_to_csv(df):
106
+ return df.to_csv().encode('utf-8')
107
+
108
+ with tab1:
109
+ if st.button("Reset Data/Load Data", key='reset1'):
110
+ # Clear values from *all* all in-memory and on-disk data caches:
111
+ # i.e. clear values from both square and cube
112
+ st.cache_data.clear()
113
+ st.dataframe(team_frame.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
114
+ st.download_button(
115
+ label="Export Projections",
116
+ data=convert_df_to_csv(team_frame),
117
+ file_name='NBA_DFS_team_frame.csv',
118
+ mime='text/csv',
119
+ key='team_frame',
120
+ )
121
+
122
+ with tab2:
123
+ if st.button("Reset Data/Load Data", key='reset2'):
124
+ # Clear values from *all* all in-memory and on-disk data caches:
125
+ # i.e. clear values from both square and cube
126
+ st.cache_data.clear()
127
+ team_var1 = st.multiselect('View specific team?', options = props_frame['Team'].unique(), key = 'prop_teamvar')
128
+ if team_var1:
129
+ props_frame = props_frame[props_frame['Team'].isin(team_var1)]
130
+ props_frame = props_frame.set_index('player')
131
+ st.dataframe(props_frame.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
132
+ st.download_button(
133
+ label="Export Projections",
134
+ data=convert_df_to_csv(props_frame),
135
+ file_name='NBA_DFS_props_frame.csv',
136
+ mime='text/csv',
137
+ key='props_frame',
138
+ )
139
+
140
+ with tab3:
141
+ st.write("The Stat specific models are currently not accurate due to an API issue. Apoligies!")
142
+ st.info('The Over and Under percentages are a compositve percentage based on simulations, historical performance, and implied probabilities, and may be different than you would expect based purely on the median projection. Likewise, the Edge of a bet is not the only indicator of if you should make the bet or not as the suggestion is using a base acceptable threshold to determine how much edge you should have for each stat category.')
143
+ if st.button("Reset Data/Load Data", key='reset3'):
144
+ # Clear values from *all* all in-memory and on-disk data caches:
145
+ # i.e. clear values from both square and cube
146
+ st.cache_data.clear()
147
+ col1, col2 = st.columns([1, 5])
148
+
149
+ with col2:
150
+ df_hold_container = st.empty()
151
+ info_hold_container = st.empty()
152
+ plot_hold_container = st.empty()
153
+ export_container = st.empty()
154
+
155
+ with col1:
156
+ prop_type_var = st.selectbox('Select prop category', options = ['Points', 'Assists', 'Rebounds', 'Points + Assists', 'Points + Rebounds', 'Points + Rebounds + Assists'])
157
+
158
+ if st.button('Simulate Prop Category'):
159
+ with col2:
160
+
161
+ with st.spinner('Wait for it...'):
162
+
163
+ with df_hold_container.container():
164
+
165
+ if prop_type_var == "Points":
166
+ player_df = load_stat_specific(points_overall)
167
+ prop_df = load_props(props_overall)
168
+ prop_df = prop_df[['Player', 'points', 'over_points_line', 'under_points_line']]
169
+ prop_df = prop_df.loc[prop_df['points'] > 0]
170
+ prop_df['Over'] = np.where(prop_df['over_points_line'] < 0, (-(prop_df['over_points_line'])/((-(prop_df['over_points_line']))+100)), 100/(prop_df['over_points_line']+100))
171
+ prop_df['Under'] = np.where(prop_df['under_points_line'] < 0, (-(prop_df['under_points_line'])/((-(prop_df['under_points_line']))+100)), 100/(prop_df['under_points_line']+100))
172
+ prop_df.rename(columns={"points": "Prop"}, inplace = True)
173
+ df = pd.merge(player_df, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
174
+ df.rename(columns={"weighted%": "weighted"}, inplace = True)
175
+ elif prop_type_var == "Assists":
176
+ player_df = load_stat_specific(assists_overall)
177
+ prop_df = load_props(props_overall)
178
+ prop_df = prop_df[['Player', 'assists', 'over_assists_line', 'under_assists_line']]
179
+ prop_df = prop_df.loc[prop_df['assists'] > 0]
180
+ prop_df['Over'] = np.where(prop_df['over_assists_line'] < 0, (-(prop_df['over_assists_line'])/((-(prop_df['over_assists_line']))+100)), 100/(prop_df['over_assists_line']+100))
181
+ prop_df['Under'] = np.where(prop_df['under_assists_line'] < 0, (-(prop_df['under_assists_line'])/((-(prop_df['under_assists_line']))+100)), 100/(prop_df['under_assists_line']+100))
182
+ prop_df.rename(columns={"assists": "Prop"}, inplace = True)
183
+ df = pd.merge(player_df, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
184
+ df.rename(columns={"weighted%": "weighted"}, inplace = True)
185
+ elif prop_type_var == "Rebounds":
186
+ player_df = load_stat_specific(rebounds_overall)
187
+ prop_df = load_props(props_overall)
188
+ prop_df = prop_df[['Player', 'rebounds', 'over_rebounds_line', 'under_rebounds_line']]
189
+ prop_df = prop_df.loc[prop_df['rebounds'] > 0]
190
+ prop_df['Over'] = np.where(prop_df['over_rebounds_line'] < 0, (-(prop_df['over_rebounds_line'])/((-(prop_df['over_rebounds_line']))+100)), 100/(prop_df['over_rebounds_line']+100))
191
+ prop_df['Under'] = np.where(prop_df['under_rebounds_line'] < 0, (-(prop_df['under_rebounds_line'])/((-(prop_df['under_rebounds_line']))+100)), 100/(prop_df['under_rebounds_line']+100))
192
+ prop_df.rename(columns={"rebounds": "Prop"}, inplace = True)
193
+ df = pd.merge(player_df, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
194
+ df.rename(columns={"weighted%": "weighted"}, inplace = True)
195
+ elif prop_type_var == "Points + Assists":
196
+ player_df = load_stat_specific(pa_overall)
197
+ prop_df = load_props(props_overall)
198
+ prop_df = prop_df[['Player', 'points_assists', 'over_points_assists_line', 'under_points_assists_line']]
199
+ prop_df = prop_df.loc[prop_df['points_assists'] > 0]
200
+ prop_df['Over'] = np.where(prop_df['over_points_assists_line'] < 0, (-(prop_df['over_points_assists_line'])/((-(prop_df['over_points_assists_line']))+100)), 100/(prop_df['over_points_assists_line']+100))
201
+ prop_df['Under'] = np.where(prop_df['under_points_assists_line'] < 0, (-(prop_df['under_points_assists_line'])/((-(prop_df['under_points_assists_line']))+100)), 100/(prop_df['under_points_assists_line']+100))
202
+ prop_df.rename(columns={"points_assists": "Prop"}, inplace = True)
203
+ df = pd.merge(player_df, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
204
+ df.rename(columns={"weighted%": "weighted"}, inplace = True)
205
+ elif prop_type_var == "Points + Rebounds":
206
+ player_df = load_stat_specific(pr_overall)
207
+ prop_df = load_props(props_overall)
208
+ prop_df = prop_df[['Player', 'points_rebounds', 'over_points_rebounds_line', 'under_points_rebounds_line']]
209
+ prop_df = prop_df.loc[prop_df['points_rebounds'] > 0]
210
+ prop_df['Over'] = np.where(prop_df['over_points_rebounds_line'] < 0, (-(prop_df['over_points_rebounds_line'])/((-(prop_df['over_points_rebounds_line']))+100)), 100/(prop_df['over_points_rebounds_line']+100))
211
+ prop_df['Under'] = np.where(prop_df['under_points_rebounds_line'] < 0, (-(prop_df['under_points_rebounds_line'])/((-(prop_df['under_points_rebounds_line']))+100)), 100/(prop_df['under_points_rebounds_line']+100))
212
+ prop_df.rename(columns={"points_rebounds": "Prop"}, inplace = True)
213
+ prop_df = prop_df[['Player', 'Prop', 'Over', 'Under']]
214
+ df = pd.merge(player_df, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
215
+ df.rename(columns={"weighted%": "weighted"}, inplace = True)
216
+ elif prop_type_var == "Points + Rebounds + Assists":
217
+ player_df = load_stat_specific(pra_overall)
218
+ prop_df = load_props(props_overall)
219
+ prop_df = prop_df[['Player', 'points_rebounds_assists', 'over_points_rebounds_assists_line', 'under_points_rebounds_assists_line']]
220
+ prop_df = prop_df.loc[prop_df['points_rebounds_assists'] > 0]
221
+ prop_df['Over'] = np.where(prop_df['over_points_rebounds_assists_line'] < 0, (-(prop_df['over_points_rebounds_assists_line'])/((-(prop_df['over_points_rebounds_assists_line']))+100)), 100/(prop_df['over_points_rebounds_assists_line']+100))
222
+ prop_df['Under'] = np.where(prop_df['under_points_rebounds_assists_line'] < 0, (-(prop_df['under_points_rebounds_assists_line'])/((-(prop_df['under_points_rebounds_assists_line']))+100)), 100/(prop_df['under_points_rebounds_assists_line']+100))
223
+ prop_df.rename(columns={"points_rebounds_assists": "Prop"}, inplace = True)
224
+ prop_df = prop_df[['Player', 'Prop', 'Over', 'Under']]
225
+ df = pd.merge(player_df, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
226
+ df.rename(columns={"weighted%": "weighted"}, inplace = True)
227
+
228
+ prop_dict = dict(zip(df.Player, df.Prop))
229
+ over_dict = dict(zip(df.Player, df.Over))
230
+ under_dict = dict(zip(df.Player, df.Under))
231
+ weighted_dict = dict(zip(df.Player, df.weighted))
232
+
233
+ total_sims = 1000
234
+
235
+ df.replace("", 0, inplace=True)
236
+
237
+ if prop_type_var == "Points":
238
+ df['Median'] = df['Points']
239
+ elif prop_type_var == "Assists":
240
+ df['Median'] = df['Assists']
241
+ elif prop_type_var == "Rebounds":
242
+ df['Median'] = df['Rebounds']
243
+ elif prop_type_var == "Points + Assists":
244
+ df['Median'] = df['Points + Assists']
245
+ elif prop_type_var == "Points + Rebounds":
246
+ df['Median'] = df['Points + Rebounds']
247
+ elif prop_type_var == "Points + Rebounds + Assists":
248
+ df['Median'] = df['Points + Rebounds + Assists']
249
+
250
+ flex_file = df
251
+ flex_file['Floor'] = flex_file['Median'] * .20
252
+ flex_file['Ceiling'] = flex_file['Median'] + (flex_file['Median'] * .20)
253
+ flex_file['STD'] = (flex_file['Median'] / 4)
254
+ flex_file['Prop'] = flex_file['Player'].map(prop_dict)
255
+ flex_file = flex_file[['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD']]
256
+
257
+ hold_file = flex_file
258
+ overall_file = flex_file
259
+ prop_file = flex_file
260
+
261
+ overall_players = overall_file[['Player']]
262
+
263
+ for x in range(0,total_sims):
264
+ prop_file[x] = prop_file['Prop']
265
+
266
+ prop_file = prop_file.drop(['Player', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
267
+ prop_file.astype('int').dtypes
268
+
269
+ for x in range(0,total_sims):
270
+ overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD'])
271
+
272
+ overall_file=overall_file.drop(['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
273
+ overall_file.astype('int').dtypes
274
+
275
+ players_only = hold_file[['Player']]
276
+
277
+ player_outcomes = pd.merge(players_only, overall_file, left_index=True, right_index=True)
278
+
279
+ prop_check = (overall_file - prop_file)
280
+
281
+ players_only['Mean_Outcome'] = overall_file.mean(axis=1)
282
+ players_only['Weighted_over'] = players_only['Player'].map(weighted_dict)
283
+ players_only['Weighted_under'] = 1 - players_only['Player'].map(weighted_dict)
284
+ players_only['10%'] = overall_file.quantile(0.1, axis=1)
285
+ players_only['90%'] = overall_file.quantile(0.9, axis=1)
286
+ players_only['Over'] = prop_check[prop_check >= 1].count(axis=1)/float(total_sims)
287
+ players_only['Imp Over'] = players_only['Player'].map(over_dict)
288
+ players_only['Over%'] = players_only[["Over", "Weighted_over", "Imp Over"]].mean(axis=1)
289
+ players_only['Under'] = prop_check[prop_check < 1].count(axis=1)/float(total_sims)
290
+ players_only['Imp Under'] = players_only['Player'].map(under_dict)
291
+ players_only['Under%'] = players_only[["Under", "Weighted_under", "Imp Under"]].mean(axis=1)
292
+ players_only['Prop'] = players_only['Player'].map(prop_dict)
293
+ players_only['Prop_avg'] = players_only['Prop'].mean() / 100
294
+ players_only['prop_threshold'] = np.where(.25 - players_only['Prop_avg'] < .10, .10, .25 - players_only['Prop_avg'])
295
+ players_only = players_only.loc[players_only['Mean_Outcome'] > 0]
296
+ players_only['Over_diff'] = players_only['Over%'] - players_only['Imp Over']
297
+ players_only['Under_diff'] = players_only['Under%'] - players_only['Imp Under']
298
+ players_only['Bet_check'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], players_only['Over_diff'] , players_only['Under_diff'])
299
+ players_only['Bet_suggest'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], "Over" , "Under")
300
+ players_only['Bet?'] = np.where(players_only['Bet_check'] >= players_only['prop_threshold'], players_only['Bet_suggest'], "No Bet")
301
+ players_only['Edge'] = players_only['Bet_check']
302
+
303
+ players_only['Player'] = hold_file[['Player']]
304
+
305
+ final_outcomes = players_only[['Player', 'Prop', 'Mean_Outcome', 'Imp Over', 'Over%', 'Imp Under', 'Under%', 'Bet?', 'Edge']]
306
+
307
+ final_outcomes = final_outcomes.sort_values(by='Edge', ascending=False)
308
+
309
+ final_outcomes = final_outcomes.set_index('Player')
310
+
311
+ with df_hold_container:
312
+ df_hold_container = st.empty()
313
+ st.dataframe(final_outcomes.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
314
+ with export_container:
315
+ export_container = st.empty()
316
+ st.download_button(
317
+ label="Export Projections",
318
+ data=convert_df_to_csv(final_outcomes),
319
+ file_name='NBA_DFS_prop_proj.csv',
320
+ mime='text/csv',
321
+ key='prop_proj',
322
+ )
323
+ with tab4:
324
+ st.info('Coming soon!')