lace.Engine.edit_cell
- Engine.edit_cell(row: str | int, col: str | int, value)
Edit the value of a cell in the table.
- Parameters:
row (row index) – The row index of the cell to edit
col (column index) – The column index of the cell to edit
value (value) – The new value at the cell
Examples
Change a surprising value
>>> from lace.examples import Animals >>> animals = Animals() >>> # top five most surprisingly fierce animals >>> animals.surprisal('fierce') \ ... .sort('surprisal', descending=True) \ ... .head(5) shape: (5, 3) ┌────────────┬────────┬───────────┐ │ index ┆ fierce ┆ surprisal │ │ --- ┆ --- ┆ --- │ │ str ┆ u8 ┆ f64 │ ╞════════════╪════════╪═══════════╡ │ pig ┆ 1 ┆ 1.574539 │ │ buffalo ┆ 1 ┆ 1.240631 │ │ rhinoceros ┆ 1 ┆ 1.076105 │ │ collie ┆ 0 ┆ 0.72471 │ │ chimpanzee ┆ 1 ┆ 0.697159 │ └────────────┴────────┴───────────┘ >>> # change pig to not fierce >>> animals.edit_cell('pig', 'fierce', 0) >>> animals.surprisal('fierce') \ ... .sort('surprisal', descending=True) \ ... .head(5) shape: (5, 3) ┌────────────┬────────┬───────────┐ │ index ┆ fierce ┆ surprisal │ │ --- ┆ --- ┆ --- │ │ str ┆ u8 ┆ f64 │ ╞════════════╪════════╪═══════════╡ │ buffalo ┆ 1 ┆ 1.240631 │ │ rhinoceros ┆ 1 ┆ 1.076105 │ │ collie ┆ 0 ┆ 0.72471 │ │ chimpanzee ┆ 1 ┆ 0.697159 │ │ chihuahua ┆ 1 ┆ 0.614058 │ └────────────┴────────┴───────────┘
Set a value to missing
>>> animals.edit_cell('pig', 'fierce', None) >>> # by default impute fills computes only missing values >>> animals.impute('fierce') shape: (1, 3) ┌───────┬────────┬─────────────┐ │ index ┆ fierce ┆ uncertainty │ │ --- ┆ --- ┆ --- │ │ str ┆ u8 ┆ f64 │ ╞═══════╪════════╪═════════════╡ │ pig ┆ 0 ┆ 0.094179 │ └───────┴────────┴─────────────┘