Takes a dataset and returns a new dataset with a new column added or inserted into it. If the columnIndex argument is omitted, the column will be appended to the end of the dataset.

Datasets are immutable, which means they cannot be directly modified once created. Instead, this scripting function returns a new dataset with some modification applied, which must be assigned to a variable to be used. See Altering a Dataset.

system.dataset.addColumn(dataset, [colIndex], col, colName, colType)

  • Parameters

Dataset dataset - The starting dataset. Please be aware that this dataset will not actually be modified (datasets are immutable), but rather will be the starting point for creating a new dataset.

Integer colIndex - The index (starting at 0) at which to insert the new column. Will throw an IndexError if less than zero or greater than the length of the dataset. If omitted, the new column will be appended to the end. [optional]

List[Any] col - A Python sequence representing the data for the new column. Its length must equal the number of rows in the dataset.

String colName - The name of the column.

Type colType - The type of the of the column. The type can be a Python builtin type, such as str , intfloat, or a Java class, such as java.util.Date.

  • Returns

Dataset - A new dataset with the new column inserted or appended.

  • Scope

Gateway, Vision Client, Perspective Session

# This example will work on a Button component on a Vision window, given two Vision bar charts with default values.
# The script takes the dataset from Bar Chart 1, adds a column of integers called Center Area to the end of the existing data,
# and displays the new dataset in Bar Chart 2.
ds1 = event.source.parent.getComponent('Bar Chart 1').data
colCount = ds1.getColumnCount()
columnName = "Center Area"
columnData = []
for i in range(ds1.getRowCount()):
 columnData.append(i* 10)
ds2 = system.dataset.addColumn(ds1, colCount, columnData, columnName, int)
event.source.parent.getComponent('Bar Chart 2').data = ds2
# This example will update a dataset tag by prepending an index column
path = [default]Dataset Tag"

dataset = system.tag.readBlocking(["path])[0].value
length = dataset.getRowCount()
valueList = []

for i in range(length):

newDataset = system.dataset.addColumn(dataset, 0, valueList, "index", int)

system.tag.writeBlocking(["path"], [newDataset])

system dataset addColumn, dataset.addColumn