Loop through Dataset and subtract columns

Hey guys,

So I have a dataset as such:
Bin1Mat Bin1Act Bin1Targ
Sand 1715 1700
Sand 1705 1700
Sand 1698 1700

Is there any good was to swift through this dataset and subtract the actual weights from the target weight and add each result to a new dataset?

Thanks a lot

There is a pretty good example of this in the documentation for system.dataset.addColumn. Should be able to mostly copy paste and then return the data to whatever is using it.


Something like this? This will only work with a pydataset, you would need to convert it back and forth to use in a table or tag.

d = [['Sand',1715,1700],['Sand',1705,1700],['Sand',1698,1700]]
r = [[x[0],x[1],x[2],x[1]-x[2]] for x in d]

I’m a bit biased towards my view() expression function, from Simulation Aids. The binding would look like this:

view("Select *, Bin1Act-Bin1Targ As Bin1Delta", {Root Container.path.to.source.data})

I used that addcolumn function and I think I am close.
Here is my code so far, the issue I am having now is that I want 24 new columns at the end of the existing dataset and right now it is only creating one new column at the end of the existing dataset.
Its like it runs through the loop and puts the last iteration in the existing dataset.

sTime = system.tag.read("[Furnace 51]Dashboard/StartTime")
eTime = system.tag.read("[Furnace 51]Dashboard/EndTime")
batch = system.db.runNamedQuery(“BatchQuery”,{“StartTime”:sTime.value,“EndTime”:eTime.value})
y = 1
actCol = 2
targCol = 3
newbatch =

while y != 25:

colCount = batch.getColumnCount()
columnName = "Bin"+str(y)+"Err"
columnData = []

for i in range(batch.getRowCount()):
	val1 = batch.getValueAt(i,int(actCol))
	val2 = batch.getValueAt(i,int(targCol))
	columnData.append(float(val1) - float(val2))
newbatch = system.dataset.addColumn(batch, colCount, columnData, columnName, float)

y = y + 1
actCol = actCol + 3
targCol = targCol + 3