fumitoh / modelx

Use Python like a spreadsheet!
https://modelx.io
GNU Lesser General Public License v3.0
96 stars 21 forks source link

Understanding function #10

Closed neelansh27 closed 4 years ago

neelansh27 commented 5 years ago

I don't understand the meaning of: • param_cols (optional) • names_col (optional) • param_rows (optional) • space_param_order • cell_param_order (optional)

in the function- new_space_fromexcel(book, range, sheet=None, name=None, names_row=None, param_cols=None, space_param_order=None, cells_param_order=None, transpose=False, names_col=None, param_rows=None)

Can you please explain what they do in layman language?

fumitoh commented 5 years ago

Take this file for example: https://github.com/fumitoh/modelx/blob/master/modelx/tests/core/data/testdata.xlsx

space = s.new_space_from_excel(
    book="testdata.xlsx",
    range_="C3:H24",
    sheet="TestSpaceTables",
    names_row=0,
    param_cols=[0, 1],
    names_col=1,
    param_rows=[1],
    space_param_order=[1],
    cells_param_order=[2, 0]
)

param_cols=[0, 1] because Year and Product columns indicate parameters. param_rows=[1] because Sex row indicates a parameter. names_col=1 because the name of the parameter Sex is in column 1.

You want the spaces and cells to have the parameters in this order: Space[Product].Cells1[Sex, Year]

The space parameter = Product whose param_cols index is 1 (2nd element in param_cols), which corresponds to space_param_order=[1], The Cells1's 1st parameter = Sex whose param_rows index is 0 (1st element in param_rows) + param_cols length(2), which corresponds to cells_param_order=2, The Cells1's 2nd parameter = Year whose param_cols index is 0 (1st element in param_cols), which corresponds to cells_param_order=0