James McCool commited on
Commit
97f24d7
·
1 Parent(s): 6b3074f

Refactor selected rows handling in app.py: streamline the process of selecting and displaying top rows for each stack, enhancing user interaction and visibility of portfolio data.

Browse files
Files changed (1) hide show
  1. app.py +25 -23
app.py CHANGED
@@ -920,32 +920,34 @@ with tab3:
920
  else:
921
  portfolio_copy = st.session_state['download_portfolio'].copy()
922
  st.table(portfolio_copy)
923
- # Create a list to store selected rows
924
- selected_rows = []
925
-
926
- # For each stack, select the top N rows based on the count value
927
- for stack in unique_stacks:
928
- if stack in st.session_state.stack_multipliers:
929
- count = int(st.session_state.stack_multipliers[stack])
930
- # Get rows for this stack
931
- stack_rows = portfolio_copy[portfolio_copy['Stack'] == stack]
932
- # Sort by median and take top N rows
933
- top_rows = stack_rows.nlargest(count, sort_var)
934
- selected_rows.append(top_rows)
935
-
936
- # Combine all selected rows
937
- portfolio_copy = pd.concat(selected_rows)
938
-
939
- st.table(portfolio_copy)
940
-
941
- # Update export_file with filtered data
942
- export_file = portfolio_copy.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
 
947
  submitted = st.form_submit_button("Submit")
948
  if submitted:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
949
  st.write('Export portfolio updated!')
950
  st.table(export_file)
951
 
 
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:
926
+ # Create a list to store selected rows
927
+ selected_rows = []
928
+
929
+ # For each stack, select the top N rows based on the count value
930
+ for stack in unique_stacks:
931
+ if stack in st.session_state.stack_multipliers:
932
+ count = int(st.session_state.stack_multipliers[stack])
933
+ # Get rows for this stack
934
+ stack_rows = portfolio_copy[portfolio_copy['Stack'] == stack]
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
+ portfolio_copy = pd.concat(selected_rows)
943
+
944
+ st.table(portfolio_copy)
945
+
946
+ # Update export_file with filtered data
947
+ export_file = portfolio_copy.copy()
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