James McCool
commited on
Commit
·
7deab18
1
Parent(s):
25703b9
Refactor load_contest_file function to improve player data processing
Browse files- Adjusted the player indexing in the DataFrame to start from 1, ensuring accurate mapping of player positions.
- Simplified the logic for splitting player entries by removing unnecessary handling of empty strings.
- These changes enhance data integrity and contribute to a better user experience within the application.
global_func/load_contest_file.py
CHANGED
@@ -37,16 +37,13 @@ def load_contest_file(upload, sport):
|
|
37 |
return None
|
38 |
|
39 |
# Create columns for each player
|
40 |
-
for i in range(max_players):
|
41 |
-
|
42 |
-
df[i] = df['Lineup'].str.split(',').str[i].fillna('').str.strip()
|
43 |
# Remove position indicators from the end of each entry
|
44 |
df[i] = df[i].str.replace(r'\s+(' + '|'.join(pos_values) + r')$', '', regex=True)
|
45 |
-
# Replace empty strings with a meaningful value if desired
|
46 |
-
# df[i] = df[i].replace('', 'Empty') # Uncomment if you want to use 'Empty' instead of empty strings
|
47 |
|
48 |
if sport == 'MLB':
|
49 |
-
df = df.rename(columns={
|
50 |
try:
|
51 |
df['Own'] = df['Own'].str.replace('%', '').astype(float)
|
52 |
except:
|
|
|
37 |
return None
|
38 |
|
39 |
# Create columns for each player
|
40 |
+
for i in range(1, max_players):
|
41 |
+
df[i] = df['Lineup'].str.split(',').str[i].str.strip()
|
|
|
42 |
# Remove position indicators from the end of each entry
|
43 |
df[i] = df[i].str.replace(r'\s+(' + '|'.join(pos_values) + r')$', '', regex=True)
|
|
|
|
|
44 |
|
45 |
if sport == 'MLB':
|
46 |
+
df = df.rename(columns={1: '1B', 2: '2B', 3: '3B', 4: 'C', 5: 'OF1', 6: 'OF2', 7: 'OF3', 8: 'SP1', 9: 'SP2', 10: 'SS'})
|
47 |
try:
|
48 |
df['Own'] = df['Own'].str.replace('%', '').astype(float)
|
49 |
except:
|