# Trying to extract tag data to make a dataset

**URL:** <https://forum.inductiveautomation.com/t/trying-to-extract-tag-data-to-make-a-dataset/77526>\
**Category:** Ignition\
**Created:** [August 7, 2023, 3:02pm UTC](https://forum.inductiveautomation.com/t/trying-to-extract-tag-data-to-make-a-dataset/77526 "2023-08-07T15:02:32Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joseph\_Alcide](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@Joseph\_Alcide](https://forum.inductiveautomation.com/u/Joseph_Alcide)\
**Post date:** [August 7, 2023, 3:02pm UTC](https://forum.inductiveautomation.com/t/trying-to-extract-tag-data-to-make-a-dataset/77526/1 "2023-08-07T15:02:32Z")

</div>

'''data = system.tag.browse("[default]DataMemory")  
headers = data.getResults()

keys\_to\_keep = ["name","value"]

filtered\_list = [  
{key: dct[key] for key in keys\_to\_keep}  
for dct in headers  
]

for dictionary in filtered\_list:  
for key, value\_list in dictionary.iteritems():  
dictionary[key] = [value\_list[0]]

print(filtered\_list)  
'''  
Hello All,

Currentky trying to extract tag data from a path to convert it to a dataset. For the value part of the tag though, it prints as the following:

[{'name': u'Flow Rate', 'value': [6, Good, Mon Aug 07 09:20:51 CDT 2023 (1691418051279)]}, {'name': u'Pressure', 'value': [2, Good, Mon Aug 07 09:20:59 CDT 2023 (1691418059829)]}, {'name': u'Temperature', 'value': [3, Good, Mon Aug 07 09:21:07 CDT 2023 (1691418067736)]}]

I would like to remove all the data from the value list except for the value itself. What I tried didn't work due to the BasicQualifiedValue object being unscriptable. Any ideas on how to do this differently that would work? Thank you so much in advance!

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 7, 2023, 3:07pm UTC](https://forum.inductiveautomation.com/t/trying-to-extract-tag-data-to-make-a-dataset/77526/2 "2023-08-07T15:07:22Z")

</div>

Instead of typing the single quotes, just use the `</>` button and paste your code inside the ticks provided.

You have a list of qualified values, to get to the value you have to extract it.

```auto
for dictionary in filtered_list:
    for key,value_list in dictionary.iteritems():
        dictionary[key] = [value_list[0].value]

```

---

<div class="post-metadata">

**Author:** ![Joseph\_Alcide](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@Joseph\_Alcide](https://forum.inductiveautomation.com/u/Joseph_Alcide)\
**Post date:** [August 7, 2023, 3:36pm UTC](https://forum.inductiveautomation.com/t/trying-to-extract-tag-data-to-make-a-dataset/77526/3 "2023-08-07T15:36:27Z")

</div>

```auto
# script builder. You may modify this script, but if you do,
# you will not be able to use the navigation builder to update
# this script without overwriting your changes.

data = system.tag.browse("[default]DataMemory")
headers = data.getResults()

keys_to_keep = ["name","value"]

filtered_list = [
	{key: dct[key] for key in keys_to_keep}
	for dct in headers
]

for dictionary in filtered_list:
	for key, value_list in dictionary.iteritems():
		dictionary[key] = [value_list[0].value]
		
print(filtered_list)
```

---

<div class="post-metadata">

**Author:** ![Joseph\_Alcide](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@Joseph\_Alcide](https://forum.inductiveautomation.com/u/Joseph_Alcide)\
**Post date:** [August 7, 2023, 3:36pm UTC](https://forum.inductiveautomation.com/t/trying-to-extract-tag-data-to-make-a-dataset/77526/4 "2023-08-07T15:36:51Z")

</div>

I got the following error: AttributeError: 'unicode' object has no attribute 'value'

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [August 7, 2023, 3:59pm UTC](https://forum.inductiveautomation.com/t/trying-to-extract-tag-data-to-make-a-dataset/77526/5 "2023-08-07T15:59:44Z")

</div>

Can you post the values of `[default]DataMemory` and `data.getResults()` so we can test your script in Script Console?

---

<div class="post-metadata">

**Author:** ![Joseph\_Alcide](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@Joseph\_Alcide](https://forum.inductiveautomation.com/u/Joseph_Alcide)\
**Post date:** [August 7, 2023, 4:14pm UTC](https://forum.inductiveautomation.com/t/trying-to-extract-tag-data-to-make-a-dataset/77526/6 "2023-08-07T16:14:44Z")

</div>

```auto
{u'fullPath': [default]DataMemory/Flow Rate, u'formatString': u'#,##0.##', u'hasChildren': False, u'dataType': Int4, u'name': u'Flow Rate', u'tagType': AtomicTag, u'attributes': [], u'valueSource': u'memory', u'value': [6, Good, Mon Aug 07 09:20:51 CDT 2023 (1691418051279)]}, {u'fullPath': [default]DataMemory/Pressure, u'formatString': u'#,##0.##', u'hasChildren': False, u'dataType': Int4, u'name': u'Pressure', u'tagType': AtomicTag, u'attributes': [], u'valueSource': u'memory', u'value': [2, Good, Mon Aug 07 09:20:59 CDT 2023 (1691418059829)]}, {u'fullPath': [default]DataMemory/Temperature, u'formatString': u'#,##0.##', u'hasChildren': False, u'dataType': Int4, u'name': u'Temperature', u'tagType': AtomicTag, u'attributes': [], u'valueSource': u'memory', u'value': [3, Good, Mon Aug 07 09:21:07 CDT 2023 (1691418067736)]}]
```

---

<div class="post-metadata">

**Author:** ![Joseph\_Alcide](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@Joseph\_Alcide](https://forum.inductiveautomation.com/u/Joseph_Alcide)\
**Post date:** [August 7, 2023, 4:15pm UTC](https://forum.inductiveautomation.com/t/trying-to-extract-tag-data-to-make-a-dataset/77526/7 "2023-08-07T16:15:27Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/4/f4108f2a113ab8345efe73af1d19c6408f11d501.png)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [August 7, 2023, 4:22pm UTC](https://forum.inductiveautomation.com/t/trying-to-extract-tag-data-to-make-a-dataset/77526/8 "2023-08-07T16:22:21Z")

</div>

That's not valid JSON. How did you generate it? You should have **right-clicked** on DataMemory and selected **Copy JSON** from the context menu.

---

<div class="post-metadata">

**Author:** ![Joseph\_Alcide](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@Joseph\_Alcide](https://forum.inductiveautomation.com/u/Joseph_Alcide)\
**Post date:** [August 7, 2023, 6:26pm UTC](https://forum.inductiveautomation.com/t/trying-to-extract-tag-data-to-make-a-dataset/77526/9 "2023-08-07T18:26:29Z")

</div>

Issue resolved, needed syntax is filtered\_data[0]['value'].value

---

<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:** [August 7, 2023, 6:41pm UTC](https://forum.inductiveautomation.com/t/trying-to-extract-tag-data-to-make-a-dataset/77526/10 "2023-08-07T18:41:48Z")

</div>

I feel like you're making things way more complicated than they actually are.  
I'd propose an alternative, but I can't even figure out what you're trying to do !  
Can you give me an example of input and expected output ?

---

<div class="post-metadata">

**Author:** ![Joseph\_Alcide](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@Joseph\_Alcide](https://forum.inductiveautomation.com/u/Joseph_Alcide)\
**Post date:** [August 7, 2023, 6:44pm UTC](https://forum.inductiveautomation.com/t/trying-to-extract-tag-data-to-make-a-dataset/77526/11 "2023-08-07T18:44:53Z")

</div>

> [@Joseph\_Alcide](#):
>
> ```auto
> for dictionary in filtered_list:
> for key, value_list in dictionary.iteritems():
> dictionary[key] = [value_list[0].value]
> 
> ```

Lets say I have three tags: Pressure, Temperature, Flow Rate. Each of them have their own value. I want to collect those tags and their values, and then make the names of the tags the header for a dataset, and make the values the data for a dataset. I want to then save this dataset as a new dataset type tag. I just want the value itself from the tag though, not the tag quality and timestamp that come with it.

---

<div class="post-metadata">

**Author:** ![Joseph\_Alcide](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@Joseph\_Alcide](https://forum.inductiveautomation.com/u/Joseph_Alcide)\
**Post date:** [August 7, 2023, 6:45pm UTC](https://forum.inductiveautomation.com/t/trying-to-extract-tag-data-to-make-a-dataset/77526/12 "2023-08-07T18:45:37Z")

</div>

Apologies for the confusion

---

<div class="post-metadata">

**Author:** ![Joseph\_Alcide](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@Joseph\_Alcide](https://forum.inductiveautomation.com/u/Joseph_Alcide)\
**Post date:** [August 7, 2023, 6:52pm UTC](https://forum.inductiveautomation.com/t/trying-to-extract-tag-data-to-make-a-dataset/77526/13 "2023-08-07T18:52:18Z")

</div>

```auto
# script builder. You may modify this script, but if you do,
# you will not be able to use the navigation builder to update
# this script without overwriting your changes.

data = system.tag.browse("[default]DataMemory")
headers = data.getResults()
print (headers)

keys_to_keep = ["name","value"]

filtered_list = [
	{key: dct[key] for key in keys_to_keep}
	for dct in headers
]

new_data = []
for item in filtered_list:
	modified_item = {"name": item["name"], "value": item["value"].value}
	new_data.append(modified_item)
	
newlod = [{d['name']: d['value']} for d in new_data]	
headers, data = zip(*[d.items()[0] for d in newlod])
ds = system.dataset.toDataSet(headers, [data])

print(ds)
event.source.parent.getComponent('Power Table').data = ds

```

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [August 7, 2023, 7:01pm UTC](https://forum.inductiveautomation.com/t/trying-to-extract-tag-data-to-make-a-dataset/77526/14 "2023-08-07T19:01:38Z")

</div>

What are you doing with the dataset? What's the final objective?

---

<div class="post-metadata">

**Author:** ![Joseph\_Alcide](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@Joseph\_Alcide](https://forum.inductiveautomation.com/u/Joseph_Alcide)\
**Post date:** [August 7, 2023, 7:15pm UTC](https://forum.inductiveautomation.com/t/trying-to-extract-tag-data-to-make-a-dataset/77526/15 "2023-08-07T19:15:17Z")

</div>

Append the second dataset to the first dataset with the same column names.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [August 7, 2023, 7:16pm UTC](https://forum.inductiveautomation.com/t/trying-to-extract-tag-data-to-make-a-dataset/77526/16 "2023-08-07T19:16:13Z")

</div>

And then do what? Display?

---

<div class="post-metadata">

**Author:** ![Joseph\_Alcide](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@Joseph\_Alcide](https://forum.inductiveautomation.com/u/Joseph_Alcide)\
**Post date:** [August 7, 2023, 7:16pm UTC](https://forum.inductiveautomation.com/t/trying-to-extract-tag-data-to-make-a-dataset/77526/17 "2023-08-07T19:16:23Z")

</div>

Yes

---

<div class="post-metadata">

**Author:** ![Joseph\_Alcide](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@Joseph\_Alcide](https://forum.inductiveautomation.com/u/Joseph_Alcide)\
**Post date:** [August 7, 2023, 7:17pm UTC](https://forum.inductiveautomation.com/t/trying-to-extract-tag-data-to-make-a-dataset/77526/18 "2023-08-07T19:17:47Z")

</div>

Realizing now though that when you send the dataset to a tag, its no longer a type '\<type 'com.inductiveautomation.ignition.common.BasicDataset'\>', its now a \<type 'java.util.ArrayList'\> so I am unsure what to do.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 7, 2023, 7:21pm UTC](https://forum.inductiveautomation.com/t/trying-to-extract-tag-data-to-make-a-dataset/77526/19 "2023-08-07T19:21:39Z")

</div>

You already have the tags, why does this dataset need to be a tag as well?

Just build the dataset at point of use.

```auto
paths = ['path/to/tag1','path/to/tag2','path/to/tag3']

tagValues = [qv.v for qv in system.tag.readBlocking(paths)]
headers = [path.split('/')[-1:] for path in paths]
ds = system.dataset.toDataSet(headers,[tagValues])

```

---

<div class="post-metadata">

**Author:** ![Joseph\_Alcide](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@Joseph\_Alcide](https://forum.inductiveautomation.com/u/Joseph_Alcide)\
**Post date:** [August 7, 2023, 7:23pm UTC](https://forum.inductiveautomation.com/t/trying-to-extract-tag-data-to-make-a-dataset/77526/20 "2023-08-07T19:23:02Z")

</div>

Because I have them generating from two different buttons, so have to be able to store the first dataset in a tag. Also because I will need to convert each dataset back into a list of dicts at some point later.

[Next page](https://forum.inductiveautomation.com/t/trying-to-extract-tag-data-to-make-a-dataset/77526.md?page=2)
