File size: 1,417 Bytes
d04558f 5db8a23 d04558f 5db8a23 d04558f 5db8a23 d04558f 5db8a23 9e80538 5db8a23 9e80538 d04558f 9e80538 d04558f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
import streamlit as st
import numpy as np
import pandas as pd
import time
from fuzzywuzzy import process
## import global functions
from global_func.clean_player_name import clean_player_name
def load_file(upload):
pos_values = ['P', 'C', '1B', '2B', '3B', 'SS', 'OF']
if upload is not None:
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
df = raw_df[['EntryId', 'EntryName', 'TimeRemaining', 'Points', 'Lineup', 'Player', 'Roster Position', '%Drafted', 'FPTS']]
df = df.rename(columns={'Roster Position': 'Pos', '%Drafted': 'Own'})
df['Lineup'] = df['Lineup'].replace(pos_values, [',']*len(pos_values), regex=True)
df['Lineup'] = df['Lineup'].str.split(',')
position_dict = dict(zip(df['Player'], df['Pos']))
ownership_dict = dict(zip(df['Player'], df['Own']))
entry_list = list(set(df['EntryName']))
entry_list.sort()
return df, position_dict, ownership_dict, entry_list
except Exception as e:
st.error(f'Error loading file: {str(e)}')
return None
return None |