iode.ComputedTable.__setitem__

ComputedTable.__setitem__(key: Tuple[int | str, int | str], value: float)[source]

Assign a new value to a cell. May modify the values of other cells.

A cell is not editable if:

  1. the corresponding column contains on operation on periods or files

  2. the corresponding column does not refer to the current workspace

  3. the corresponding LEC expression from the original table starts with 0+

  4. the corresponding LEC expression from the original table does not refer to at least one variable

Parameters:
key: tuple(int or str, int or str)

Row and column to access the cell. Row and column can be passed either as position (int) or as name (str).

value: float

New value of the cell.

Notes

When the corresponding LEC expression involves more than one variable, only the value of the first variable is modified.

Examples

>>> from iode import SAMPLE_DATA_DIR
>>> from iode import Table, comments, variables
>>> comments.load(f"{SAMPLE_DATA_DIR}/fun.cmt")
Loading .../fun.cmt
317 objects loaded 
>>> variables.load(f"{SAMPLE_DATA_DIR}/fun.var")
Loading .../fun.var
394 objects loaded
>>> title = "Example Table"
>>> lecs = ["Q_F", "Q_I", "Q_F/Q_I", "ln(Q_I+Q_F)", "KNFF", "KNFF[-1]", "3+ln(10)", "0+KNFF"]
>>> table = Table(2, title, lecs)
>>> table
DIVIS | 1             |
TITLE |       "Example Table"
----- | ---------------------------
CELL  |               |     "#S"
----- | ---------------------------
CELL  | "Q_F"         |         Q_F
CELL  | "Q_I"         |         Q_I
CELL  | "Q_F/Q_I"     |     Q_F/Q_I
CELL  | "ln(Q_I+Q_F)" | ln(Q_I+Q_F)
CELL  | "KNFF"        |        KNFF
CELL  | "KNFF[-1]"    |    KNFF[-1]
CELL  | "3+ln(10)"    |    3+ln(10)
CELL  | "0+KNFF"      |      0+KNFF

nb lines: 12
nb columns: 2
language: 'ENGLISH'
gridx: 'MAJOR'
gridy: 'MAJOR'
graph_axis: 'VALUES'
graph_alignment: 'LEFT'
>>> # compute table
>>> computed_table = table.compute("(2010;2010/2009)[1;2]:2", extra_files=f"{SAMPLE_DATA_DIR}/ref.av")
>>> computed_table
 line title \ period[file]  | 2010[1]  | 2010[2]  | 2010/2009[1] | 2010/2009[2] | 2011[1]  | 2011[2]  | 2011/2010[1] | 2011/2010[2]
------------------------------------------------------------------------------------------------------------------------------------
Q_F                         |  5842.74 |  5725.89 |         1.90 |         1.90 |  5930.75 |  5812.13 |         1.51 |         1.51
Q_I                         |  1093.37 |  1071.50 |         0.89 |         0.89 |  1114.60 |  1092.30 |         1.94 |         1.94
Q_F/Q_I                     |     5.34 |     5.34 |         1.00 |         1.00 |     5.32 |     5.32 |        -0.43 |        -0.43
ln(Q_I+Q_F)                 |     8.84 |     8.82 |         0.20 |         0.20 |     8.86 |     8.84 |         0.18 |         0.18
KNFF                        | 11525.01 | 11294.51 |         2.05 |         2.05 | 11736.78 | 11502.05 |         1.84 |         1.84
KNFF[-1]                    | 11293.85 | 11067.97 |         2.82 |         2.82 | 11525.01 | 11294.51 |         2.05 |         2.05
3+ln(10)                    |     5.30 |     5.30 |         0.00 |         0.00 |     5.30 |     5.30 |         0.00 |         0.00
0+KNFF                      | 11525.01 | 11294.51 |         2.05 |         2.05 | 11736.78 | 11502.05 |         1.84 |         1.84
>>> # set cell value by position
>>> computed_table[1, 4] = 1114.0
>>> computed_table[1, 4]
1114.0
>>> # set cell value by labels
>>> computed_table["Q_I", "2011[1]"] = 1115.0
>>> computed_table["Q_I", "2011[1]"]
1115.0
>>> # warning: when the corresponding LEC expression involves more than one variable, 
>>> #          only the value of the first variable is modified.
>>> # variables values before:
>>> variables["Q_F", "2011Y1"]
5930.747852857564
>>> variables["Q_I", "2011Y1"]
1115.0
>>> # update cell of the computed table
>>> computed_table["Q_F/Q_I", "2011[1]"] = 5.28
>>> # variables values after:
>>> #   Q_F/Q_I = new_value 
>>> #   Q_F = new_value * Q_I 
>>> variables["Q_F", "2011Y1"]
5887.20023393631
>>> variables["Q_I", "2011Y1"]
1115.0