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. Datasets are immutable, so it is important to realize that this function does not actually add a column to a dataset. You'll need to do something with the new dataset that this function creates to achieve something useful. If the columnIndex argument is omitted, the column will be appended to the end of the dataset.
Client Permission Restrictions
This scripting function has no Client Permission restrictions.
Syntax
system.dataset.addColumn(dataset [, colIndex], col, colName, colType)
Parameters
Type | Parameter | Description |
---|---|---|
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. |
int | 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] |
PySequence | 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. |
PyType | colType | The type of the of the column. The type can be the Python equivalent of String, Long, Double, Short, Integer, Float, Boolean, null, or java.util.Date if they exist. |
Returns
Dataset - A new dataset with the new column inserted or appended.
Scope
All
Code Examples
Example 1
# This example 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