DFS_Portfolio_Manager / global_func /load_dk_fd_file.py
James McCool
Refactor import statements across multiple files to replace 'fuzzywuzzy' with 'rapidfuzz' for improved performance and consistency in string matching functionality. Additionally, clean up unused imports in app.py and related global functions to enhance code clarity and maintainability.
d9db89f
raw
history blame
1.33 kB
import streamlit as st
import numpy as np
import pandas as pd
import time
from rapidfuzz import process
import re
def load_dk_fd_file(lineups, csv_file):
df = csv_file.copy()
try:
name_dict = dict(zip(df['Name + ID'], df['Name']))
except:
name_dict = dict(zip(df['Id'], df['Nickname']))
# Now load and process the lineups file
try:
clean_name = re.sub(r' \(\d+\)', '', lineups.name)
print(clean_name)
print(lineups.name)
if clean_name.endswith('.csv'):
lineups_df = pd.read_csv(lineups)
elif clean_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
print(lineups_df)
try:
lineups_df = lineups_df.drop(columns=['Entry ID', 'Contest Name', 'Contest ID', 'Entry Fee'])
except:
pass
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