# Change Column Name in Dataset

**URL:** <https://forum.inductiveautomation.com/t/change-column-name-in-dataset/66867>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [November 23, 2022, 5:48pm UTC](https://forum.inductiveautomation.com/t/change-column-name-in-dataset/66867 "2022-11-23T17:48:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [November 23, 2022, 5:48pm UTC](https://forum.inductiveautomation.com/t/change-column-name-in-dataset/66867/1 "2022-11-23T17:48:39Z")

</div>

Is there a relatively easy way to rebuild a dataset with new column names?

I will have a dataset with a dynamic set of columns (between 2 and 10 really), lets say it looks like this:

| Timestamp | Temperature | Pressure |
| --- | --- | --- |
| XXX | XXX | XXX |
| XXX | XXX | XXX |
| XXX | XXX | XXX |

I need to change it to the following:

| column0 | column1 | column2 |
| --- | --- | --- |
| XXX | XXX | XXX |
| XXX | XXX | XXX |
| XXX | XXX | XXX |

I know its possible for me to iterate through each column and swap it out like this:

```auto
newColumns = ["column%s" % index for index in range(dataset.getColumnCount())]
for index, column in enumerate(dataset.getColumnNames()):
	dataset = system.dataset.addColumn(dataset, index, dataset.getColumnAsList(index), "column%s" % index, dataset.getColumnType(index))

dataset = system.dataset.filterColumns(dataset, newColumns)

```

I am just curious if there is a better way, I know they are immutable, so I am guessing not, but just curious.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [November 23, 2022, 5:56pm UTC](https://forum.inductiveautomation.com/t/change-column-name-in-dataset/66867/2 "2022-11-23T17:56:55Z")

</div>

[BasicDataset](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.22/com/inductiveautomation/ignition/common/BasicDataset.html#%3Cinit%3E(java.util.List,java.util.List,com.inductiveautomation.ignition.common.Dataset)) has a constructor that accepts another dataset:

```python
from com.inductiveautomation.ignition.common import BasicDataset
newColumns = ["column%s" % index for index in range(dataset.getColumnCount())]
dataset = BasicDataset(newColumns, dataset.columnTypes, dataset)

```

If the original was a 'streaming' dataset type, this will collect it into memory, but your original code was doing that too, so 🤷‍♂️

---

<div class="post-metadata">

**Author:** ![earnhartj84](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/earnhartj84/32/29405_2.png) [@earnhartj84](https://forum.inductiveautomation.com/u/earnhartj84)\
**Post date:** [February 15, 2023, 2:51pm UTC](https://forum.inductiveautomation.com/t/change-column-name-in-dataset/66867/3 "2023-02-15T14:51:00Z")

</div>

IGN 8.1  
here is the Source code i used.  
Vision , Regular Table component.  
with Tag history .

* * *

table = event.source.parent.getComponent("Table")  
data = table.data  
from com.inductiveautomation.ignition.common import BasicDataset  
newColumns = ["Time","U1 Volts","U2 Volts","U3 Volts","I1 Amps","I2 Amps","I3 Amps","P1 Power KW","P2 Power KW,""P3 Power KW","Total Power KW","PF1","PF2","PF3","Total PF"]  
dataset = BasicDataset(newColumns, data.columnTypes, data)  
csv = system.dataset.toCSV(dataset)  
file = system.file.saveFile("export.csv", "csv", "Comma Separated Values")  
if file:  
system.file.writeFile(file, csv)

* * *

_note_ new columns string names must match how many columns you have in your table.  
this was used on a image for mouse click script to export data to a excel / CSV file.
