James McCool
Add functionality for player name cleaning and CSV mismatch detection
d04558f
raw
history blame
1.02 kB
import streamlit as st
import numpy as np
import pandas as pd
import time
from fuzzywuzzy import process
def load_ss_file(lineups, csv_file):
df = csv_file.copy()
try:
name_dict = dict(zip(df['ID'], df['Name']))
except:
name_dict = dict(zip(df['Id'], df['Nickname']))
# Now load and process the lineups file
try:
if lineups.name.endswith('.csv'):
lineups_df = pd.read_csv(lineups)
elif lineups.name.endswith(('.xls', '.xlsx')):
lineups_df = pd.read_excel(lineups)
else:
st.error('Please upload either a CSV or Excel file for lineups')
return None, None
export_df = lineups_df.copy()
# Map the IDs to names
for col in lineups_df.columns:
lineups_df[col] = lineups_df[col].map(name_dict)
return export_df, lineups_df
except Exception as e:
st.error(f'Error loading lineups file: {str(e)}')
return None, None