Search code examples
pythonarrayspandasnumpypyomo

How to construct a table (matrix) with two lists and arrays of data?


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?


Solution

  • Why not:

    print(pd.DataFrame(Beta, FixedInputs, Croptypes))