datascience.tables.Table.relabeled¶
- Table.relabeled(label, new_label)[source]¶
Return a new table with
label
specifying column label(s) replaced by correspondingnew_label
.- Args:
label
– (str or array of str) The label(s) ofcolumns to be changed.
new_label
– (str or array of str): The new label(s) ofcolumns to be changed. Same number of elements as label.
- Raises:
ValueError
– iflabel
does not exist intable, or if the
label
andnew_label
are not not of equal length. Also, raised iflabel
and/ornew_label
are notstr
.
- Returns:
New table with
new_label
in place oflabel
.
>>> 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.