James McCool
commited on
Commit
·
8a5c645
1
Parent(s):
1689df1
Refactor lineup processing in `load_file.py` to enhance data extraction and cleanliness
Browse files- Updated the logic to dynamically determine the maximum number of players in any lineup, allowing for more flexible data handling.
- Cleaned up the DataFrame by dropping unnecessary columns before returning, improving the usability of the output data.
- global_func/load_file.py +7 -2
global_func/load_file.py
CHANGED
@@ -33,16 +33,21 @@ def load_file(upload):
|
|
33 |
df['Lineup'] = df['Lineup'].str.replace(r'\b(' + '|'.join(pos_values) + r')\b', r'\1,', regex=True)
|
34 |
|
35 |
# Split into individual columns and remove position indicators
|
36 |
-
|
|
|
|
|
|
|
|
|
37 |
df[i] = df['Lineup'].str.split(',').str[i].str.strip()
|
38 |
# Remove position indicators from the end of each entry
|
39 |
df[i] = df[i].str.replace(r'\s+(' + '|'.join(pos_values) + r')$', '', regex=True)
|
40 |
position_dict = dict(zip(df['Player'], df['Pos']))
|
41 |
ownership_dict = dict(zip(df['Player'], df['Own']))
|
|
|
42 |
entry_list = list(set(df['BaseName']))
|
43 |
entry_list.sort()
|
44 |
|
45 |
-
return
|
46 |
except Exception as e:
|
47 |
st.error(f'Error loading file: {str(e)}')
|
48 |
return None
|
|
|
33 |
df['Lineup'] = df['Lineup'].str.replace(r'\b(' + '|'.join(pos_values) + r')\b', r'\1,', regex=True)
|
34 |
|
35 |
# Split into individual columns and remove position indicators
|
36 |
+
# First, determine the maximum number of players in any lineup
|
37 |
+
max_players = df['Lineup'].str.split(',').str.len().max()
|
38 |
+
|
39 |
+
# Create columns for each player
|
40 |
+
for i in range(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 |
position_dict = dict(zip(df['Player'], df['Pos']))
|
45 |
ownership_dict = dict(zip(df['Player'], df['Own']))
|
46 |
+
cleaned_df = df.drop(columns=['EntryId', 'EntryName', 'TimeRemaining', 'Points', 'Lineup', 'Player', 'Pos', 'Own', 'FPTS'])
|
47 |
entry_list = list(set(df['BaseName']))
|
48 |
entry_list.sort()
|
49 |
|
50 |
+
return cleaned_df, position_dict, ownership_dict, entry_list
|
51 |
except Exception as e:
|
52 |
st.error(f'Error loading file: {str(e)}')
|
53 |
return None
|