Spaces:
Running
Running
James McCool
commited on
Commit
·
4b41aad
1
Parent(s):
e091f4e
Enhance data handling in app.py by expanding player data mapping
Browse filesUpdated the renaming of columns in sd_roo_data to include additional ownership metrics. Enhanced the sd_hold_frame with new mappings for 'Order', 'Hand', 'Opp', 'Team_Total', and 'Opp_Total', incorporating error handling for missing values. This change improves data clarity and ensures comprehensive player information is available for further processing.
app.py
CHANGED
@@ -128,7 +128,31 @@ def init_baselines():
|
|
128 |
|
129 |
sd_roo_data = player_frame.drop(columns=['_id'])
|
130 |
sd_roo_data['Salary'] = sd_roo_data['Salary'].astype(int)
|
131 |
-
sd_roo_data = sd_roo_data.rename(columns={'Own': 'Own%'})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
|
133 |
collection = db["Scoring_Percentages"]
|
134 |
cursor = collection.find()
|
|
|
128 |
|
129 |
sd_roo_data = player_frame.drop(columns=['_id'])
|
130 |
sd_roo_data['Salary'] = sd_roo_data['Salary'].astype(int)
|
131 |
+
sd_roo_data = sd_roo_data.rename(columns={'Own': 'Own%', 'Small_Own': 'Small Field Own%', 'Large_Own': 'Large Field Own%', 'Cash_Own': 'Cash Own%'})
|
132 |
+
sd_hold_frame = sd_roo_data.copy()
|
133 |
+
|
134 |
+
sd_hold_frame['Order'] = np.where(sd_hold_frame['pos_group'] == 'Hitters', sd_hold_frame['Player'].map(RHP_Info.set_index('Player')['Order']), 0)
|
135 |
+
sd_hold_frame['Hand'] = np.where(sd_hold_frame['pos_group'] == 'Hitters', sd_hold_frame['Player'].map(RHP_Info.set_index('Player')['bats']), sd_hold_frame['Player'].map(RHH_Info.set_index('Player')['Hand']))
|
136 |
+
try:
|
137 |
+
sd_hold_frame['Opp'] = sd_hold_frame['Team'].map(RHH_Info.drop_duplicates(subset='Team').set_index('Team')['Opp'])
|
138 |
+
except:
|
139 |
+
sd_hold_frame['Opp'] = np.nan
|
140 |
+
try:
|
141 |
+
sd_hold_frame['Team_Total'] = sd_hold_frame['Team'].map(RHH_Info.drop_duplicates(subset='Team').set_index('Opp')['Opp_TT'])
|
142 |
+
except:
|
143 |
+
sd_hold_frame['Team_Total'] = np.nan
|
144 |
+
try:
|
145 |
+
sd_hold_frame['Opp_Total'] = sd_hold_frame['Team'].map(RHH_Info.drop_duplicates(subset='Team').set_index('Team')['Opp_TT'])
|
146 |
+
except:
|
147 |
+
sd_hold_frame['Opp_Total'] = np.nan
|
148 |
+
sd_roo_data.insert(3, 'Opp', sd_hold_frame['Opp'])
|
149 |
+
sd_roo_data.insert(4, 'Hand', sd_hold_frame['Hand'])
|
150 |
+
try:
|
151 |
+
sd_roo_data.insert(5, 'Order', sd_hold_frame['Order'].astype(int))
|
152 |
+
except:
|
153 |
+
sd_roo_data.insert(5, 'Order', sd_hold_frame['Order'])
|
154 |
+
sd_roo_data.insert(6, 'Team_Total', sd_hold_frame['Team_Total'])
|
155 |
+
sd_roo_data.insert(7, 'Opp_Total', sd_hold_frame['Opp_Total'])
|
156 |
|
157 |
collection = db["Scoring_Percentages"]
|
158 |
cursor = collection.find()
|