# Dataset find missing value

**URL:** <https://forum.inductiveautomation.com/t/dataset-find-missing-value/38367>\
**Category:** Ignition\
**Tags:** ignition80, vision, scripting\
**Created:** [September 3, 2020, 8:09pm UTC](https://forum.inductiveautomation.com/t/dataset-find-missing-value/38367 "2020-09-03T20:09:45Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [September 3, 2020, 8:09pm UTC](https://forum.inductiveautomation.com/t/dataset-find-missing-value/38367/1 "2020-09-03T20:09:45Z")

</div>

Has anyone created a script to find a missing value between the min/max of a dataset? Basically, if a certain column has a min value of 1 and max value of 100, what’s the best way in script to determine if there are any missing values between those with a base of 1.

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [September 3, 2020, 8:13pm UTC](https://forum.inductiveautomation.com/t/dataset-find-missing-value/38367/2 "2020-09-03T20:13:33Z")

</div>

Nevermind, Google was my friend:

```auto
lst = [1, 2, 4, 6, 7, 9, 10] 

for x in range(lst[0], lst[-1]+1):  
	if x not in lst:
		print x

```

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [September 3, 2020, 8:20pm UTC](https://forum.inductiveautomation.com/t/dataset-find-missing-value/38367/3 "2020-09-03T20:20:19Z")

</div>

Is your list always going to be sorted for you?

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [September 3, 2020, 8:25pm UTC](https://forum.inductiveautomation.com/t/dataset-find-missing-value/38367/4 "2020-09-03T20:25:59Z")

</div>

Oh, good point. Maybe, maybe not. Yep, the code I stole won’ t work well unless it’s sorted.

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [September 3, 2020, 8:34pm UTC](https://forum.inductiveautomation.com/t/dataset-find-missing-value/38367/5 "2020-09-03T20:34:44Z")

</div>

Any reason this approach is unwise?

```auto
lst = [4, 1, 2, 6, 7, 9, 10] 
sortList = sorted(lst)

for x in range(sortList[0], sortList[-1]+1):  
	if x not in sortList:
		print x

```

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [September 3, 2020, 8:45pm UTC](https://forum.inductiveautomation.com/t/dataset-find-missing-value/38367/6 "2020-09-03T20:45:53Z")

</div>

Should be fine unless you have an exceptionally large number of rows.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [September 3, 2020, 8:47pm UTC](https://forum.inductiveautomation.com/t/dataset-find-missing-value/38367/7 "2020-09-03T20:47:16Z")

</div>

That’s actually preferable to `lst.sort()` because it leaves the original alone. The biggest problem you could encounter here is unexpected types in the column. As long as you’re confident this will always receive integers, then you’re fine. If it ever encounters `str` representations (“2”), then you’ll encounter a TypeError.

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [September 3, 2020, 9:05pm UTC](https://forum.inductiveautomation.com/t/dataset-find-missing-value/38367/8 "2020-09-03T21:05:40Z")

</div>

Thanks guys. I’m confident it will always be integers and the size will be fairly small, most is 200 rows or so.

---

<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:** [September 4, 2020, 10:06am UTC](https://forum.inductiveautomation.com/t/dataset-find-missing-value/38367/9 "2020-09-04T10:06:08Z")

</div>

Using min and max might save you a step. Also, you don’t really need to add one to the upper end of the range because we know the max value of the list already exists. Three possible examples:

```python
lst = [4, 1, 2, 6, 7, 8, 10] 

print 'For loop'
for x in range(min(lst), max(lst)):  
	if x not in lst:
		print x

print '---'

print 'List comprehension'
print [x for x in range(min(lst), max(lst)) if x not in lst]

print '---'

print 'Using sets'
print set(range(min(lst), max(lst))) - set(lst)

```

Output:

```nohighlight
For loop
3
5
9
---
List comprehension
[3, 5, 9]
---
Using sets
set([3, 5, 9])

```

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [September 4, 2020, 9:26pm UTC](https://forum.inductiveautomation.com/t/dataset-find-missing-value/38367/10 "2020-09-04T21:26:15Z")

</div>

Thanks, I took your advice. I actually didn’t need min() as I always want to start at 1 (which I overlooked), so I ended up doing this…

```auto
for x in range(1, max(list)):

```

It works well. Thanks everyone for your input, much appreciated.
