Transpose Table Header

Is there a way to transpose the contents of a table, in other words make the columns show as row headers and all the data be listed left to right for that header instead of top to bottom?

HEADER1 field 1
HEADER 2 field 2
HEADER 3 field 3

instead of

field 1 field 2 field 3


I’m sure I’ve commented on this topic before…
Yep, a quick search of the forum with just the key word ‘transpose’ yields this:

I think this should work -

pyDS = system.dataset.toPyDataSet(ds)
l = [list(x) for x in pyDS] #convert to a list of lists
trList = [list(i) for i in zip(*l)]
newDS = system.dataset.toDataSet(trList[0], trList[1:]) #headers are the first row, the rest is data

You might have to use [str(z) for z in list(i)] instead of just list(i) depending on your data though. If that doesn’t work well for you you’ll probably have to go more in depth like @pturmel’s method. If its super simple stuff, this should work.

Where “super simple” means “field1, field2, … fieldN all have the same datatype”, and headers are in the data instead of just the column names, yes.

Not sure how I missed that post in my searches. Thanks for the options