James McCool commited on
Commit
1277f48
·
1 Parent(s): 5a9b212

Enhance data type handling and regex replacement in grab_contest_data.py

Browse files

- Updated the data type conversion for specific columns in the lineups DataFrame to ensure they are treated as integers, improving data integrity.
- Modified the 'Lineup' replacement method to utilize regex, enhancing flexibility in player ID mapping.
- These changes contribute to ongoing efforts to streamline data processing and improve code maintainability.

Files changed (1) hide show
  1. global_func/grab_contest_data.py +3 -1
global_func/grab_contest_data.py CHANGED
@@ -65,7 +65,9 @@ def grab_contest_data(sport, contest_name, contest_id_map, contest_date_map):
65
  lineups_df = lineups_df.rename(columns={'index': 'Rank', 'points': 'Points', 'entryNameList': 'EntryName', 'lineupHash': 'Lineup'})
66
  lineups_df['EntryName'] = lineups_df['EntryName'] + ' (1/1)'
67
  lineups_df['Lineup'] = lineups_df['Lineup'].apply(lambda x: format_lineup_string(x, position_inserts))
68
- lineups_df['Lineup'] = lineups_df['Lineup'].replace(pid_map)
 
 
69
  lineups_df = lineups_df[['Rank', 'EntryId', 'EntryName', 'TimeRemaining', 'Points', 'Lineup']]
70
 
71
  total_data = lineups_df.merge(players_df, how='left', left_index=True, right_index=True)
 
65
  lineups_df = lineups_df.rename(columns={'index': 'Rank', 'points': 'Points', 'entryNameList': 'EntryName', 'lineupHash': 'Lineup'})
66
  lineups_df['EntryName'] = lineups_df['EntryName'] + ' (1/1)'
67
  lineups_df['Lineup'] = lineups_df['Lineup'].apply(lambda x: format_lineup_string(x, position_inserts))
68
+ for col in lineups_df.columns[2:]:
69
+ lineups_df[col] = lineups_df[col].astype(int)
70
+ lineups_df['Lineup'] = lineups_df['Lineup'].replace(pid_map, regex=True)
71
  lineups_df = lineups_df[['Rank', 'EntryId', 'EntryName', 'TimeRemaining', 'Points', 'Lineup']]
72
 
73
  total_data = lineups_df.merge(players_df, how='left', left_index=True, right_index=True)