0

I want to create a matrix/table that I can later retrieve. The two dimensions are: Croptypes and FixedInputs.

Croptypes = ["barley", "rapeseed", "wheat"]
FixedInputs = ["land", "labor", "capital"]
Beta = [[0.3, 0.2, 0.3], [0.1, 0.1, 0.1], [0.3, 0.2, 0.2]]

The table/matrix should look like this:

          "barley"   "rapeseed"  "wheat" 
"land"      0.3        0.2         0.3
"labor"     0.1        0.1         0.1  
"capital"   0.3        0.2         0.2

But the length of the two lists (Croptypes and FixedInputs) may change later, so I want to have a function that can create this table and does not need to be adjusted even if I change the length of the two lists.

In pyomo there is a function called tabular_writer(), is this the write function to use? if yes, can someone show me how?

or any other solutions?

1 Answers1

1

Why not:

print(pd.DataFrame(Beta, FixedInputs, Croptypes))
U13-Forward
  • 69,221
  • 14
  • 89
  • 114
  • it works! How can I convert the same matrix into a dictionary? The dictionary should look like this: dict = {(barley, land): 0.3, (barley, labor): 0.1, ...(wheat, capital):0.2} – Linmei Shang Jul 03 '19 at 09:53