Spaces:
Sleeping
Sleeping
James McCool
commited on
Commit
·
610b496
1
Parent(s):
dd63c0f
Refactor portfolio export logic in app.py: streamline the concatenation of selected rows and update the export file handling, improving data management and user experience during portfolio updates.
Browse files
app.py
CHANGED
|
@@ -919,7 +919,6 @@ with tab3:
|
|
| 919 |
portfolio_copy = st.session_state['portfolio'].copy()
|
| 920 |
else:
|
| 921 |
portfolio_copy = st.session_state['download_portfolio'].copy()
|
| 922 |
-
st.table(portfolio_copy)
|
| 923 |
|
| 924 |
submitted = st.form_submit_button("Submit")
|
| 925 |
if submitted:
|
|
@@ -935,21 +934,16 @@ with tab3:
|
|
| 935 |
# Sort by median and take top N rows
|
| 936 |
top_rows = stack_rows.nlargest(count, sort_var)
|
| 937 |
selected_rows.append(top_rows)
|
| 938 |
-
|
| 939 |
-
st.table(selected_rows)
|
| 940 |
|
| 941 |
# Combine all selected rows
|
| 942 |
-
|
| 943 |
-
|
| 944 |
-
st.table(portfolio_copy)
|
| 945 |
|
| 946 |
# Update export_file with filtered data
|
| 947 |
-
export_file =
|
| 948 |
for col in export_file.columns:
|
| 949 |
if col not in excluded_cols:
|
| 950 |
export_file[col] = export_file[col].map(st.session_state['export_dict'])
|
| 951 |
st.write('Export portfolio updated!')
|
| 952 |
-
st.table(export_file)
|
| 953 |
try:
|
| 954 |
st.download_button(label="Download Portfolio", data=export_file.to_csv(index=False), file_name="portfolio.csv", mime="text/csv")
|
| 955 |
except:
|
|
|
|
| 919 |
portfolio_copy = st.session_state['portfolio'].copy()
|
| 920 |
else:
|
| 921 |
portfolio_copy = st.session_state['download_portfolio'].copy()
|
|
|
|
| 922 |
|
| 923 |
submitted = st.form_submit_button("Submit")
|
| 924 |
if submitted:
|
|
|
|
| 934 |
# Sort by median and take top N rows
|
| 935 |
top_rows = stack_rows.nlargest(count, sort_var)
|
| 936 |
selected_rows.append(top_rows)
|
|
|
|
|
|
|
| 937 |
|
| 938 |
# Combine all selected rows
|
| 939 |
+
portfolio_concat = pd.concat(selected_rows)
|
|
|
|
|
|
|
| 940 |
|
| 941 |
# Update export_file with filtered data
|
| 942 |
+
export_file = portfolio_concat.copy()
|
| 943 |
for col in export_file.columns:
|
| 944 |
if col not in excluded_cols:
|
| 945 |
export_file[col] = export_file[col].map(st.session_state['export_dict'])
|
| 946 |
st.write('Export portfolio updated!')
|
|
|
|
| 947 |
try:
|
| 948 |
st.download_button(label="Download Portfolio", data=export_file.to_csv(index=False), file_name="portfolio.csv", mime="text/csv")
|
| 949 |
except:
|