I am using pyomo to generate my model which depends on input data from a pandas data frame. In the model, I need to add a binary variable for every pair (column, row) in the data frame for which the corresponding entry is greater than zero.
So far I am doing the following (which works) but it generates too many variables, obviously.
df = pd.read_csv(...)
cols = df.columns.tolist()
rows = df.index.tolist()
model = ConcreteModel()
model.myVars = Var(cols, rows, within=Binary, name="myVars")
What's the easiest and most elegant way to only generate a variable in myVars for c in cols and r in rows if df[c][r] > 0?