Dataset Confusion - inserting extra rows

I’m using runPrepQuery to return a dataset which I’m then sending to Excel.
I’ve been asked to insert some blank rows in to try and make it more readable, specifically when a value in a certain column changes.

Here is part of my code. data2 holds the dataset returned from the query and the column I’m looking for a change in is “Load Reference”.

[code] loadRef=""
# Loop through data
for row in data2:
if loadRef!=row[“Load Reference”]:
# Avoid gap line at the start
if loadRef!="":
# Insert gap line
# Store new load reference
loadRef=row[“Load Reference”]
# Store original data
newRows.append([row[0], row[1], row[2], str(row[3]), row[4], str(row[5])])

	# Now convert to dataset
	newData2 = system.dataset.toDataSet(["Supplier","Product","Load Reference","Machine","Description","Value"], newRows)


Now after much messing about this basically does seem to do what I want.
But is this the best way do to it? Is there an easier way?
Specifically, should I be able to do newRows.append(row) rather than they way I’ve done it, listing out every single column?
And also is there a way to easily reuse the column headers from the original dataset rather than defining them again like I have done? I tried the system.dataset.getColumnHeaders function but couldn’t get it to work.

There is nothing wrong with the way you are doing this. In fact in situations where you need to append a handful or more of new rows then this method is actually preferred. Ignition datasets are immutable so they cannot be modified after they have been created. Whenever you call a function that modifies a dataset what is actually happening behind the scenes is a new dataset is being created with all the data from the old dataset plus the changes you’re making. This process is rather inefficient when you have a lot of edits to make to a dataset.