# Delete value on the tag dataset

**URL:** <https://forum.inductiveautomation.com/t/delete-value-on-the-tag-dataset/65653>\
**Category:** Ignition\
**Created:** [October 25, 2022, 3:00pm UTC](https://forum.inductiveautomation.com/t/delete-value-on-the-tag-dataset/65653 "2022-10-25T15:00:11Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![sebastien\_ng](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sebastien_ng/32/55297_2.png) [@sebastien\_ng](https://forum.inductiveautomation.com/u/sebastien_ng)\
**Post date:** [October 25, 2022, 3:00pm UTC](https://forum.inductiveautomation.com/t/delete-value-on-the-tag-dataset/65653/1 "2022-10-25T15:00:11Z")

</div>

if I want to remove the number 20 for example in the dataset of type 4x1

NameColumn  
30  
20  
12  
10

I use this line of code:  
`dsDevice = self.view.params.listZoneDesservies # dataset`  
`dsDevice = system.dataset.deleteRow(dsDevice,self.view.params.idZone)`  
The problem is that I know the value I want to delete but not its index.  
In the dataset, each value will be unique. so if I can delete a value without knowing its index, that would be good

What function should I use to remove the value without knowing its index in the dataset?

---

<div class="post-metadata">

**Author:** ![franklepkowski](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/franklepkowski/32/4808_2.png) [@franklepkowski](https://forum.inductiveautomation.com/u/franklepkowski)\
**Post date:** [October 25, 2022, 3:33pm UTC](https://forum.inductiveautomation.com/t/delete-value-on-the-tag-dataset/65653/2 "2022-10-25T15:33:56Z")

</div>

Hello. Iterate through the dataset with a loop and use the .getValueAt function. That should do the trick.

---

<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:** [October 25, 2022, 4:44pm UTC](https://forum.inductiveautomation.com/t/delete-value-on-the-tag-dataset/65653/3 "2022-10-25T16:44:24Z")

</div>

Many possible ways to do this; here are a few:

```python
def filterDataset(dataset, valueToExclude, column=0):
	rowsToRemove = []
	for row in xrange(dataset.rowCount):
		if dataset.getValueAt(row, column) == valueToExclude:
			rowsToRemove.append(row)

	return system.dataset.deleteRows(dataset, rowsToRemove)

def filterDataset(dataset, valueToExclude, column=0):
	pds = system.dataset.toPyDataSet(dataset)

	rowsToRemove = []
	for index, row in enumerate(pds):
		if row[column] == valueToExclude:
			rowsToRemove.append(index)

	return system.dataset.deleteRows(dataset, rowsToRemove)

def filterDataset(dataset, valueToExclude, column=0):
	pds = system.dataset.toPyDataSet(dataset)

	data = []
	for index, row in enumerate(pds):
		if row[column] != valueToExclude:
			data.append(list(row))

	return system.dataset.toDataSet(list(dataset.columnNames), data)

def filterDataset(dataset, valueToExclude, column=0):
	# requires Ignition Extensions: https://forum.inductiveautomation.com/t/ignition-extensions-convenience-utilities-for-advanced-users/64615
	def filterFn(**columns):
		return columns[column] != valueToExclude

	return system.dataset.filter(dataset, filterFn)

```

---

<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:** [October 25, 2022, 5:47pm UTC](https://forum.inductiveautomation.com/t/delete-value-on-the-tag-dataset/65653/4 "2022-10-25T17:47:40Z")

</div>

I would do this:

```auto
def filterDataset(ds, exclude, column=0):
	try:
		idx = int(column)
	except:
		idx = ds.getColumnIndex(column)
	values = ds.getColumnAsList(idx)
	rowExcludes = [i for (i, v) in enumerate(values) if v == exclude]
	if rowExcludes:
		return system.dataset.deleteRows(ds, rowExcludes)
	return ds

```

Accepts a column index or a column name. Returns the original dataset if no rows matched.

---

<div class="post-metadata">

**Author:** ![sebastien\_ng](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sebastien_ng/32/55297_2.png) [@sebastien\_ng](https://forum.inductiveautomation.com/u/sebastien_ng)\
**Post date:** [October 26, 2022, 6:30am UTC](https://forum.inductiveautomation.com/t/delete-value-on-the-tag-dataset/65653/5 "2022-10-26T06:30:18Z")

</div>

here is the script i made to delete one value, it works.  
first I check if the value I want to delete exists in the dataset

```auto
dsZone = self.view.params.DeviceZone #dataset
if self.view.params.idDevice in dsZone.getColumnAsList(0):
			for i in range(dsZone.getRowCount()):
			   if dsZone.getValueAt(i, 'listDevice') == self.view.params.idDevice:	
					dsZone = system.dataset.deleteRow(dsZone,i)
					system.tag.writeBlocking([zonePath],[dsZone])
					break

```

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [October 26, 2022, 9:20am UTC](https://forum.inductiveautomation.com/t/delete-value-on-the-tag-dataset/65653/6 "2022-10-26T09:20:56Z")

</div>

> [@sebastien\_ng](#):
>
> first I check if the value I want to delete exists in the dataset

Why ? You're already doing that with the inner if.  
And if you're converting the column to a list, might as well use that to find the index instead of going through your dataset in a loop...

Use one of the scripts above. They have the added advantage of being reusable.

If you want something closer to your own code:

```python
dsZone = self.view.params.DeviceZone
index = dsZone.getColumnAsList(0).index(self.view.params.idDevice)
dsZone = system.dataset.deleteRow(dsZone, index)
system.tag.writeBlocking([zonePath], [dsZone])

```

But again, do you NEED a dataset tag for just one column ? It's been several threads were you're doing list operation on that same one column dataset, and it seems to me you could make your life simpler by using an array instead...

---

<div class="post-metadata">

**Author:** ![sebastien\_ng](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sebastien_ng/32/55297_2.png) [@sebastien\_ng](https://forum.inductiveautomation.com/u/sebastien_ng)\
**Post date:** [October 26, 2022, 9:35am UTC](https://forum.inductiveautomation.com/t/delete-value-on-the-tag-dataset/65653/8 "2022-10-26T09:35:00Z")

</div>

dsZone is a dataset that I get from a tag.

Yes I'am doing operation on that same one column dataset because the person who created the dataset type tag did not use the array. This is the reason why I'am using same type of data.

it's true that it would be easier to use array.

And I nedd delete one row not a list of value from dataset reason why I'am using **deleteRow** and not `deleteRows`

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [October 26, 2022, 9:38am UTC](https://forum.inductiveautomation.com/t/delete-value-on-the-tag-dataset/65653/9 "2022-10-26T09:38:09Z")

</div>

You can change the data type of a tag with just a few clicks.

`deleteRows(ds, [i])` will do the same thing as `deleteRows(ds, i)`.  
I wouldn't be surprised if they're just wrappers around the exact same function.

---

<div class="post-metadata">

**Author:** ![sebastien\_ng](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sebastien_ng/32/55297_2.png) [@sebastien\_ng](https://forum.inductiveautomation.com/u/sebastien_ng)\
**Post date:** [October 26, 2022, 9:51am UTC](https://forum.inductiveautomation.com/t/delete-value-on-the-tag-dataset/65653/10 "2022-10-26T09:51:40Z")

</div>

The problem this dataset is used on other script. If I change dataset as Array, I think it will cause problem. I will change to later.

---

<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:** [October 26, 2022, 12:55pm UTC](https://forum.inductiveautomation.com/t/delete-value-on-the-tag-dataset/65653/11 "2022-10-26T12:55:47Z")

</div>

> [@pascal.fragnoud](#):
>
> But again, do you NEED a dataset tag for just one column ?

You keep harping on using an array instead of a dataset. Unless you are using Perspective, and this topic is agnostic on that point (because the algorithms apply anywhere), datasets are much more platform-friendly. In particular, Vision doesn't have a client-side custom property type for arrays.

Please confine your array advice to situations where it is known that the data is only going to be used in Perspective.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [October 26, 2022, 1:00pm UTC](https://forum.inductiveautomation.com/t/delete-value-on-the-tag-dataset/65653/12 "2022-10-26T13:00:41Z")

</div>

I'll keep that in mind, sorry.

But I'm pretty sure we've established in a previous thread that he's using perspective.

---

<div class="post-metadata">

**Author:** ![sebastien\_ng](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sebastien_ng/32/55297_2.png) [@sebastien\_ng](https://forum.inductiveautomation.com/u/sebastien_ng)\
**Post date:** [October 26, 2022, 1:06pm UTC](https://forum.inductiveautomation.com/t/delete-value-on-the-tag-dataset/65653/13 "2022-10-26T13:06:22Z")

</div>

I'am using perspective
