# Transpose Table Header

**URL:** <https://forum.inductiveautomation.com/t/transpose-table-header/18064>\
**Category:** Ignition\
**Created:** [May 16, 2018, 7:21pm UTC](https://forum.inductiveautomation.com/t/transpose-table-header/18064 "2018-05-16T19:21:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [May 16, 2018, 7:21pm UTC](https://forum.inductiveautomation.com/t/transpose-table-header/18064/1 "2018-05-16T19:21:04Z")

</div>

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

HEADER1 HEADER2 HEADER3  
field 1 field 2 field 3

Thanks

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 16, 2018, 8:14pm UTC](https://forum.inductiveautomation.com/t/transpose-table-header/18064/2 "2018-05-16T20:14:51Z")

</div>

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:

> [@Transpose Rows and Columns](http://forum.inductiveautomation.com/t/transpose-rows-and-columns/14308):
>
> I have a table component displaying daily flow totals on each day of the week. It executes an sql query which returns a dataset with each item name as a column and each day as a row. For display purposes I’d like to transpose the rows and columns so that the days are displayed along the top and item names along the side. I’ve been trying to accomplish this with scripting. It seems such a simple operation but it’s proving much more difficult than I thought. Is it actually possible or does this …

---

<div class="post-metadata">

**Author:** ![mrogers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mrogers/32/4110_2.png) [@mrogers](https://forum.inductiveautomation.com/u/mrogers)\
**Post date:** [May 16, 2018, 8:17pm UTC](https://forum.inductiveautomation.com/t/transpose-table-header/18064/3 "2018-05-16T20:17:48Z")

</div>

I think this should work -

```auto
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.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 16, 2018, 8:22pm UTC](https://forum.inductiveautomation.com/t/transpose-table-header/18064/4 "2018-05-16T20:22:53Z")

</div>

> [@mrogers](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [May 17, 2018, 12:39pm UTC](https://forum.inductiveautomation.com/t/transpose-table-header/18064/5 "2018-05-17T12:39:40Z")

</div>

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