Issue in split list

[u’BP Compressors’, u’SPA Compressors’]

i need to remove u from the list . please let me know how to remove the u

The u just means it’s unicode. It’s not part of the string itself.

i need to pass that value to dataset header
[“BP compressors”, “SPA Compressors”]
how to pass like this?
please let me know how to pass this words to header

I have not had an issue using unicode strings as headers. :man_shrugging:

But, if you really need to make sure they’re string objects:

listIn = [u'BP Compressors', u'SPA Compressors']
listOut = [str(i) for i in listIn]

Out of curiosity, where is the list coming from?

i am browsing UDT tag folders for Stacked bar. i need to use folders name as header for dataset of bar

i am getting like this when i pass this to header? whats wrong in this?

Show us the code.

excl= ["Device Info"]
name = "Compressors"
temp =[]
tagstatus = []
test = []
viru = []
#dt = Total_Consumption
def browse(path, filter):
		results = system.tag.browse(path, filter)
		return results
	
res = browse('[MQTT Engine]Edge Nodes/Robertsbridge/Energy/Electric/Compressors',{'tagType': 'Folder'})
#print res
for result in res.getResults():
		if result.get("name") not in excl:
			temp.append(result.get("name"))
			#print temp
			path = browse(result.get("fullPath"),{'tagType': 'UdtInstance'})
			#print result['name']
			x = result['name']
			viru.append(x)
			#t = a.split()
			#print viru
			tagstatus.append(result["name"])
			server = ''.join(tagstatus)
			dat = system.tag.read('[MQTT Engine]Edge Nodes/Robertsbridge/Energy/Electric/Compressors/'+server+'/Total_Consumption/Total_Consumption_kW').value
			test.append(dat)
			tagstatus = []
data = test
listIn =  viru
listOut = [str(i) for i in listIn]
header = (["Label",listOut])
pyd = ([data])
out = system.dataset.toDataSet(header,pyd)
print out

#print data


i have attached picture of code also

code

Please edit your post pasting the code using this button

done please check and solve my issue

what my requirement is I need to get the UDT tags from different folders and pass the tag values to dataset**( i want headers and value to be changed dynamically depends upon the path i am choosing)**. whether i am doing in proper way or any changes need to be done to get correct output. please help me out

A couple of questions:

  • What is ‘Label’?
  • Are you wanting your end results in a wide format like what you have started, or a tall one?

Label i not given means i am getting error like this
header = [listOut]
>>> **
Traceback (most recent call last):
** File “”, line 36, in

IndexError: Row 0 doesn’t have the same number of columns as header list.

end result i want to use the dataset to stacked bar (Wide format)

You need to extend the header list, you are embedding a list within the 2nd element.

header=['label'] + listOut
1 Like

Look at the documentation here - https://docs.inductiveautomation.com/display/DOC79/system.dataset.toDataSet

It looks like your headers variable is wrong. Your headers should be a single list like ['column1', 'column2', ..., 'columnN']

However your headers variable is headers = ("Label", listOut) which would be a tuple containing a string and then a list. Your headers variable should look like ['column1', 'column2', ..., 'columnN'] as mentioned. Same with the dataset. Pretty sure you want a list of lists - that may work with a tuple but I’ve never done it with a tuple, I usually have [[row1 data], [row2 data]], ...].

The last error you posted though just means you have a different number of column headers and data columns.

OK, start with:

header = listOut

We can work on simplifying and optimizing in a bit.

In a stacked chart, the first column is considered the category, or what groups the values on each row together. You would actually need three columns.

What you require for the label of the category should be the value in the first column.