craftutils.wrap.dragons.Table.round(decimals=0)

Round numeric columns in-place to the specified number of decimals. Non-numeric columns will be ignored.

Examples

Create three columns with different types:

>>> t = Table([[1, 4, 5], [-25.55, 12.123, 85],
...     ['a', 'b', 'c']], names=('a', 'b', 'c'))
>>> print(t)
 a    b     c
--- ------ ---
  1 -25.55   a
  4 12.123   b
  5   85.0   c

Round them all to 0:

>>> t.round(0)
>>> print(t)
 a    b    c
--- ----- ---
  1 -26.0   a
  4  12.0   b
  5  85.0   c

Round column ‘a’ to -1 decimal:

>>> t.round({'a':-1})
>>> print(t)
 a    b    c
--- ----- ---
  0 -26.0   a
  0  12.0   b
  0  85.0   c

Parameters

decimals: int, dict

Number of decimals to round the columns to. If a dict is given, the columns will be rounded to the number specified as the value. If a certain column is not in the dict given, it will remain the same.