Get varying weights for portfolio analysis

I would like to make a Streamlit app which can introduce weights based on columns of my data.
I mean:

  1. I have a dataframe
  2. I would like that the user can introduce the weight he wanted based on a subset of the columns dataframe (he can select the columns he wants to perform the portfolio)
  3. calculate portfolio which is R = sommeprod(weight, Ri)

How can I make an app to introduce the weight with number of data that can varies.

Thx for your help.

Assuming selected is a list of column names:

weights = {}
for col in selected:
    weights[col] = st.number_input(label=f"{col} weight")


One more question : I have done a multi pages application. How to make data/variable from one page to be accessible to another ?


Use session_state.