import streamlit as st import pandas as pd def load_contest_file(upload, sport): pos_values = ['P', 'C', '1B', '2B', '3B', 'SS', 'OF'] if upload is not None: try: try: if upload.name.endswith('.csv'): raw_df = pd.read_csv(upload) elif upload.name.endswith(('.xls', '.xlsx')): raw_df = pd.read_excel(upload) else: st.error('Please upload either a CSV or Excel file') return None except: raw_df = upload df = raw_df[['EntryId', 'EntryName', 'TimeRemaining', 'Points', 'Lineup', 'Player', 'Roster Position', '%Drafted', 'FPTS', 'Salary', 'Team']] df = df.rename(columns={'Roster Position': 'Pos', '%Drafted': 'Own'}) # Split EntryName into base name and entry count df['BaseName'] = df['EntryName'].str.replace(r'\s*\(\d+/\d+\)$', '', regex=True) df['EntryCount'] = df['EntryName'].str.extract(r'\((\d+/\d+)\)') df['EntryCount'] = df['EntryCount'].fillna('1/1') # Default to 1/1 if no entry count # Split the lineup string by replacing position indicators with commas # Only replace position indicators that are at the start of a player entry df['Lineup'] = df['Lineup'].str.replace(r'(?