Skip to main content
Version: 8.1

system.dataset.addColumn

This function is used in Python Scripting.

Description​

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.

note

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.

Client Permission Restrictions​

This scripting function has no Client Permission restrictions.

Syntax​

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

Parameters​

TypeParameterDescription
DatasetdatasetThe 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.
IntegercolIndexThe 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]colA Python sequence representing the data for the new column. Its length must equal the number of rows in the dataset.
StringcolNameThe name of the column.
TypecolTypeThe type of the of the column. The type can be a Python builtin type, such as str , int, float, 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

Code Examples​

Code Snippet
# 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
Code Snippet
# 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):
valueList.append(i)

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

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

Keywords​

system dataset addColumn, dataset.addColumn