James McCool commited on
Commit
1ba31e0
·
1 Parent(s): 4375d7e

Improve lineup string processing in `load_file.py` for accurate position extraction

Browse files

- Enhanced the logic for replacing position indicators in the `Lineup` column to ensure only those at the start of player entries are replaced, preventing unintended modifications within player names.
- Added stripping of whitespace after splitting the `Lineup` string into individual columns, improving data cleanliness and usability.

Files changed (1) hide show
  1. global_func/load_file.py +7 -2
global_func/load_file.py CHANGED
@@ -21,9 +21,14 @@ def load_file(upload):
21
 
22
  df = raw_df[['EntryId', 'EntryName', 'TimeRemaining', 'Points', 'Lineup', 'Player', 'Roster Position', '%Drafted', 'FPTS']]
23
  df = df.rename(columns={'Roster Position': 'Pos', '%Drafted': 'Own'})
24
- df['Lineup'] = df['Lineup'].replace(pos_values, [',']*len(pos_values), regex=True)
 
 
 
 
 
25
  for i in range(0,9):
26
- df[i] = df['Lineup'].str.split(',').str[i]
27
  position_dict = dict(zip(df['Player'], df['Pos']))
28
  ownership_dict = dict(zip(df['Player'], df['Own']))
29
  entry_list = list(set(df['EntryName']))
 
21
 
22
  df = raw_df[['EntryId', 'EntryName', 'TimeRemaining', 'Points', 'Lineup', 'Player', 'Roster Position', '%Drafted', 'FPTS']]
23
  df = df.rename(columns={'Roster Position': 'Pos', '%Drafted': 'Own'})
24
+ # Split the lineup string by replacing position indicators with commas
25
+ # We need to ensure we only replace position indicators that are at the start of a player entry
26
+ # and not those that might appear within player names
27
+ df['Lineup'] = df['Lineup'].str.replace(r'\b(' + '|'.join(pos_values) + r')\b', r'\1,', regex=True)
28
+
29
+ # Split into individual columns
30
  for i in range(0,9):
31
+ df[i] = df['Lineup'].str.split(',').str[i].str.strip()
32
  position_dict = dict(zip(df['Player'], df['Pos']))
33
  ownership_dict = dict(zip(df['Player'], df['Own']))
34
  entry_list = list(set(df['EntryName']))