datascience.tables.Table.relabel¶
- Table.relabel(column_label, new_label)[source]¶
Changes the label(s) of column(s) specified by
column_label
to labels innew_label
.- Args:
column_label
– (single str or array of str) The label(s) ofcolumns to be changed to
new_label
.new_label
– (single str or array of str): The label name(s)of columns to replace
column_label
.
- Raises:
ValueError
– ifcolumn_label
is not in table, or ifcolumn_label
andnew_label
are not of equal length.TypeError
– ifcolumn_label
and/ornew_label
is notstr
.
- Returns:
Original table with
new_label
in place ofcolumn_label
.
>>> table = Table().with_columns( ... 'points', make_array(1, 2, 3), ... 'id', make_array(12345, 123, 5123)) >>> table.relabel('id', 'yolo') points | yolo 1 | 12345 2 | 123 3 | 5123 >>> table.relabel(make_array('points', 'yolo'), ... make_array('red', 'blue')) red | blue 1 | 12345 2 | 123 3 | 5123 >>> table.relabel(make_array('red', 'green', 'blue'), ... make_array('cyan', 'magenta', 'yellow', 'key')) Traceback (most recent call last): ... ValueError: Invalid arguments. column_label and new_label must be of equal length.