# Can I modify an entire column from a dataset with system.dataset.setValue()?

**URL:** <https://forum.inductiveautomation.com/t/can-i-modify-an-entire-column-from-a-dataset-with-system-dataset-setvalue/87043>\
**Category:** Ignition\
**Tags:** python, vision, scripting\
**Created:** [March 8, 2024, 3:39pm UTC](https://forum.inductiveautomation.com/t/can-i-modify-an-entire-column-from-a-dataset-with-system-dataset-setvalue/87043 "2024-03-08T15:39:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![nbautomation](https://avatars.discourse-cdn.com/v4/letter/n/3be4f8/32.png) [@nbautomation](https://forum.inductiveautomation.com/u/nbautomation)\
**Post date:** [March 8, 2024, 3:39pm UTC](https://forum.inductiveautomation.com/t/can-i-modify-an-entire-column-from-a-dataset-with-system-dataset-setvalue/87043/1 "2024-03-08T15:39:29Z")

</div>

Hi, I need to modify an entire colum from a dataset. I'm trying to do it with a cycle 'for' and 'system.dataset.setValue' but the cycle for only modified the last cell of the colum

This is my example code:

```auto
table = event.source.parent.getComponent("Table")
dataIn = system.dataset.toPyDataSet(table.data)

```

`values=[10,20,30]`

```auto
for n in range(0,2):
	table.data=system.dataset.setValue(dataIn, n, "columnIntegers", values[n])
	print( n ,"times")

```

When I run the script, only edited the last cell, which has the int 30  
And I checked the Output console and show

_0 times_  
_1 times_  
_2 times_  
I think system.dataset.setValue is not the best way but I'm noob on this  
Y tried doing the cycle 'manual' and I obtained the same result  
how can I code it?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 8, 2024, 3:51pm UTC](https://forum.inductiveautomation.com/t/can-i-modify-an-entire-column-from-a-dataset-with-system-dataset-setvalue/87043/2 "2024-03-08T15:51:23Z")

</div>

`system.dataset.setValue()` doesn't modify the source dataset. It makes a new dataset with the change request. You would need to re-assign to `dataIn` within the loop, and then assign `dataIn` to the target property after the loop is done.

That aside, this is terribly inefficient. I recommend using `system.dataset.filterColumns()` to drop the old column completely, then `system.dataset.addColumn()` to add it back with the new data. Construct just the new data in the loop (or perhaps in a list comprehension).

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 8, 2024, 4:23pm UTC](https://forum.inductiveautomation.com/t/can-i-modify-an-entire-column-from-a-dataset-with-system-dataset-setvalue/87043/3 "2024-03-08T16:23:52Z")

</div>

```python
def mapColumn(function, dataset, column):
	if isinstance(column, basestring):
		column = dataset.getColumnIndex(column)

	columnData = map(function, dataset.getColumnAsList(column))
	columnsToKeep = range(dataset.columnCount)
	columnsToKeep.pop(column)
	dsWithoutColumn = system.dataset.filterColumns(dataset, columnsToKeep)
	
	return system.dataset.addColumn(
		dsWithoutColumn, 
		column, 
		columnData, 
		dataset.getColumnName(column), 
		dataset.getColumnType(column)
	)

```

It's relatively easy to create a 'mapColumn' function composed of our base primitives. This will be pretty efficient.  
Usage is pretty simple - just declare a function that performs the calculation you want, for each value in the column, then supply it (no parenthesis!) to the mapColumn function:

```python
# usage:
def updateColumn(value):
	return value * 2

updatedDs = mapColumn(updateColumn, ds, "b")

```

On my test dataset, this does what you'd expect:

```auto
a | b | c
1 | 2 | 3
4 | 5 | 6

a | b | c
1 | 4 | 3
4 | 10 | 6

```

---

<div class="post-metadata">

**Author:** ![nbautomation](https://avatars.discourse-cdn.com/v4/letter/n/3be4f8/32.png) [@nbautomation](https://forum.inductiveautomation.com/u/nbautomation)\
**Post date:** [March 8, 2024, 5:01pm UTC](https://forum.inductiveautomation.com/t/can-i-modify-an-entire-column-from-a-dataset-with-system-dataset-setvalue/87043/4 "2024-03-08T17:01:39Z")

</div>

Thanks! It works!

---

<div class="post-metadata">

**Author:** ![nbautomation](https://avatars.discourse-cdn.com/v4/letter/n/3be4f8/32.png) [@nbautomation](https://forum.inductiveautomation.com/u/nbautomation)\
**Post date:** [March 11, 2024, 1:35pm UTC](https://forum.inductiveautomation.com/t/can-i-modify-an-entire-column-from-a-dataset-with-system-dataset-setvalue/87043/5 "2024-03-11T13:35:37Z")

</div>

Now I'm trying to do something more than Just do a calcule for a specific column.  
I have a List with float tags provided from Tags OPC (No problem obtaining this values) and I need  
to put them in specific column on the same orden  
Column/position0= List[0]  
Column/position1=List[1]  
...  
Column/position n=List[n]

Where List contain the values of tags and 'n' is a knowed parameter

I was trying with a function similar  
But I only could put the same value of the List in all rows of the column  
I'm sorry if the solution is so obvious and dumb for you. I'm new with this Framework and Python.  
Each Time I try to do somethings more complex for me

I try put the list on the first parameter but the error said "list is not calleable"  
Then I tried to do a for

```auto
for n in range(0,index_knowed):
	updatedDs = mapColumn(values[n], table.data, "GRUESO")
table.data=updatedDs

```

_TypeError: 'float' object is not callable_

Values is a list with float values.

I tried to make  
`integer_Values[n]= int(values[n])`  
inside the for but  
The error was  
_TypeError: 'int' object is not callable_

Can anyone guide me?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 11, 2024, 2:40pm UTC](https://forum.inductiveautomation.com/t/can-i-modify-an-entire-column-from-a-dataset-with-system-dataset-setvalue/87043/6 "2024-03-11T14:40:58Z")

</div>

Is this already in the dataset, or are you adding a column to the dataset?

---

<div class="post-metadata">

**Author:** ![nbautomation](https://avatars.discourse-cdn.com/v4/letter/n/3be4f8/32.png) [@nbautomation](https://forum.inductiveautomation.com/u/nbautomation)\
**Post date:** [March 11, 2024, 3:08pm UTC](https://forum.inductiveautomation.com/t/can-i-modify-an-entire-column-from-a-dataset-with-system-dataset-setvalue/87043/7 "2024-03-11T15:08:32Z")

</div>

I saw my error, the differences between the example code posted for @paul-griffith and what I needed it, it was in the map function, because I already had the List for put in the third Parameter of

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

so that I did put them and everything works

I couldn't see until now.  
Thanks 🤝🏼
