datascience.tables.Table.with_column

Table.with_column(label, values, *rest)[source]

Return a new table with an additional or replaced column.

Args:
label (str): The column label. If an existing label is used,
the existing column will be replaced in the new table.
values (single value or sequence): If a single value, every
value in the new column is values. If sequence of values, new column takes on values in values.
rest: An alternating list of labels and values describing
additional columns. See with_columns for a full description.
Raises:
ValueError: If
  • label is not a valid column name
  • if label is not of type (str)
  • values is a list/array that does not have the same
    length as the number of rows in the table.
Returns:
copy of original table with new or replaced column
>>> alphabet = Table().with_column('letter', make_array('c','d'))
>>> alphabet = alphabet.with_column('count', make_array(2, 4))
>>> alphabet
letter | count
c      | 2
d      | 4
>>> alphabet.with_column('permutes', make_array('a', 'g'))
letter | count | permutes
c      | 2     | a
d      | 4     | g
>>> alphabet
letter | count
c      | 2
d      | 4
>>> alphabet.with_column('count', 1)
letter | count
c      | 1
d      | 1
>>> alphabet.with_column(1, make_array(1, 2))
Traceback (most recent call last):
    ...
ValueError: The column label must be a string, but a int was given
>>> alphabet.with_column('bad_col', make_array(1))
Traceback (most recent call last):
    ...
ValueError: Column length mismatch. New column does not have the same number of rows as table.