James McCool
commited on
Commit
·
1c84812
1
Parent(s):
3720273
updating load_csv to handle dataframes
Browse files- app.py +1 -6
- global_func/load_csv.py +13 -10
app.py
CHANGED
|
@@ -173,11 +173,6 @@ except:
|
|
| 173 |
nfl_slate_name_lookup_fd = {}
|
| 174 |
|
| 175 |
nfl_reg_salaries = grab_nfl_reg_salaries()
|
| 176 |
-
print(nfl_reg_salaries.head(10))
|
| 177 |
-
|
| 178 |
-
print(nfl_slate_names_dk)
|
| 179 |
-
print(nfl_slate_name_lookup_dk)
|
| 180 |
-
print(dk_db_nfl_showdown_selections)
|
| 181 |
|
| 182 |
# Memory optimization helper functions
|
| 183 |
def chunk_name_matching(portfolio_names, csv_names, chunk_size=1000):
|
|
@@ -605,7 +600,7 @@ if selected_tab == 'Data Load':
|
|
| 605 |
upload_csv_col, csv_template_col = st.columns([3, 1])
|
| 606 |
if pricing_source == 'Paydirt DB':
|
| 607 |
if st.button("Load from Paydirt DB"):
|
| 608 |
-
csv_file = nfl_reg_salaries
|
| 609 |
if 'csv_file' in st.session_state:
|
| 610 |
del st.session_state['csv_file']
|
| 611 |
else:
|
|
|
|
| 173 |
nfl_slate_name_lookup_fd = {}
|
| 174 |
|
| 175 |
nfl_reg_salaries = grab_nfl_reg_salaries()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
|
| 177 |
# Memory optimization helper functions
|
| 178 |
def chunk_name_matching(portfolio_names, csv_names, chunk_size=1000):
|
|
|
|
| 600 |
upload_csv_col, csv_template_col = st.columns([3, 1])
|
| 601 |
if pricing_source == 'Paydirt DB':
|
| 602 |
if st.button("Load from Paydirt DB"):
|
| 603 |
+
csv_file = nfl_reg_salaries
|
| 604 |
if 'csv_file' in st.session_state:
|
| 605 |
del st.session_state['csv_file']
|
| 606 |
else:
|
global_func/load_csv.py
CHANGED
|
@@ -7,17 +7,20 @@ from rapidfuzz import process
|
|
| 7 |
def load_csv(upload):
|
| 8 |
if upload is not None:
|
| 9 |
try:
|
| 10 |
-
if upload.
|
| 11 |
-
df =
|
| 12 |
-
try:
|
| 13 |
-
df['Name + ID'] = df['Name'] + ' (' + df['ID'].astype(str) + ')'
|
| 14 |
-
except:
|
| 15 |
-
pass
|
| 16 |
else:
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
except Exception as e:
|
| 22 |
st.error(f'Error loading file: {str(e)}')
|
| 23 |
return None
|
|
|
|
| 7 |
def load_csv(upload):
|
| 8 |
if upload is not None:
|
| 9 |
try:
|
| 10 |
+
if isinstance(upload, pd.DataFrame):
|
| 11 |
+
df = upload.copy()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
else:
|
| 13 |
+
if upload.name.endswith('.csv'):
|
| 14 |
+
df = pd.read_csv(upload)
|
| 15 |
+
try:
|
| 16 |
+
df['Name + ID'] = df['Name'] + ' (' + df['ID'].astype(str) + ')'
|
| 17 |
+
except:
|
| 18 |
+
pass
|
| 19 |
+
else:
|
| 20 |
+
st.error('Please upload either a CSV or Excel file')
|
| 21 |
+
return None
|
| 22 |
+
|
| 23 |
+
return df
|
| 24 |
except Exception as e:
|
| 25 |
st.error(f'Error loading file: {str(e)}')
|
| 26 |
return None
|