I am developing the code in Ignition software using Jython/Python 2 scripts. We need to read data from csv file that has two delimiters "," in header and "\t" in data. The code we use are:
file_path = r'T:\test1.csv'
csvData = csv.reader(open(file_path, 'r'))
header = csvData.next() # Skip the fist row
dataset = system.dataset.toDataSet(header,list(csvData))
calcwindow.rootContainer.getComponent('Power Table').data = dataset
After applying this code we get this: Power Table
Question are how can we separate the data so that all rows and columns match with csv.reader as ignition do not support panda or re :(
Update the code and now it separate data correctly:
csvData = csv.reader(open(file_path, 'r'),delimiter=',')
header = csvData.next()# Skip the fist row
for line in csvData:
str1 = "".join(line) #removes commas
#print str1
parts = str1.split("\t")
print parts
dataset = system.dataset.toDataSet(header,list(parts))
calcwindow.rootContainer.getComponent('Power Table').data = dataset
, but the error code came up:
Row 0 doesn't have the same number of columns as header list.
Any suggestions??
Thanks Igor