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.565845  │
│ rhinoceros ┆ 1      ┆ 1.094639  │
│ buffalo    ┆ 1      ┆ 1.094639  │
│ chihuahua  ┆ 1      ┆ 0.802085  │
│ chimpanzee ┆ 1      ┆ 0.723817  │
└────────────┴────────┴───────────┘
>>>  # 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       │
╞════════════╪════════╪═══════════╡
│ rhinoceros ┆ 1      ┆ 1.094639  │
│ buffalo    ┆ 1      ┆ 1.094639  │
│ chihuahua  ┆ 1      ┆ 0.802085  │
│ chimpanzee ┆ 1      ┆ 0.723817  │
│ dalmatian  ┆ 0      ┆ 0.594919  │
└────────────┴────────┴───────────┘

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.07593     │
└───────┴────────┴─────────────┘