datascience.tables.Table.relabeled

Table.relabeled(label, new_label)[source]

Return a new table with label specifying column label(s) replaced by corresponding new_label.

Args:
label – (str or array of str) The label(s) of

columns to be changed.

new_label – (str or array of str): The new label(s) of

columns to be changed. Same number of elements as label.

Raises:
ValueError – if label does not exist in

table, or if the label and new_label are not not of equal length. Also, raised if label and/or new_label are not str.

Returns:

New table with new_label in place of label.

>>> tiles = Table().with_columns('letter', make_array('c', 'd'),
...    'count', make_array(2, 4))
>>> tiles
letter | count
c      | 2
d      | 4
>>> tiles.relabeled('count', 'number')
letter | number
c      | 2
d      | 4
>>> tiles  # original table unmodified
letter | count
c      | 2
d      | 4
>>> tiles.relabeled(make_array('letter', 'count'),
...   make_array('column1', 'column2'))
column1 | column2
c       | 2
d       | 4
>>> tiles.relabeled(make_array('letter', 'number'),
...  make_array('column1', 'column2'))
Traceback (most recent call last):
    ...
ValueError: Invalid labels. Column labels must already exist in table in order to be replaced.