# Rename the column of a dataset

**URL:** <https://forum.inductiveautomation.com/t/rename-the-column-of-a-dataset/56043>\
**Category:** Ignition\
**Created:** [February 11, 2022, 5:34pm UTC](https://forum.inductiveautomation.com/t/rename-the-column-of-a-dataset/56043 "2022-02-11T17:34:32Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [February 11, 2022, 5:34pm UTC](https://forum.inductiveautomation.com/t/rename-the-column-of-a-dataset/56043/1 "2022-02-11T17:34:32Z")

</div>

Hi,  
I have dataset [61R×4C]

I want to rename the column 4 name . How to do that using script?

@JordanCClark any idea to do?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [February 11, 2022, 5:52pm UTC](https://forum.inductiveautomation.com/t/rename-the-column-of-a-dataset/56043/2 "2022-02-11T17:52:59Z")

</div>

Depends on where the dataset is coming from. The easiest way is to change it at the source.

If you really want to do this in script then you would have to rebuild the Dataset

```auto
ds = *Your Data*
headers = system.dataset.getColumnHeaders()
headers[3] = "New Column Name"
values = [[ds.getValueAt(row,col) for col in range(ds.columnCount)] for row in range(ds.rowCount)]
ds = system.dataset.toDataSet(headers,values)

```

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [February 11, 2022, 5:55pm UTC](https://forum.inductiveautomation.com/t/rename-the-column-of-a-dataset/56043/3 "2022-02-11T17:55:18Z")

</div>

Thanks i will try it out

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [February 11, 2022, 5:57pm UTC](https://forum.inductiveautomation.com/t/rename-the-column-of-a-dataset/56043/4 "2022-02-11T17:57:17Z")

</div>

Check edit, modified the script, because you need a list of lists.

More Coffee, needed apparently.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [February 11, 2022, 6:12pm UTC](https://forum.inductiveautomation.com/t/rename-the-column-of-a-dataset/56043/5 "2022-02-11T18:12:23Z")

</div>

Please don’t ping users looking for help unless it’s related to something they have already answered. That’s not fair to them unless you’re going to pay for their work.

* * *

Set your query to return **Document** format.  
Add a script transform and modify the following code. (You can test it in the Script Console.

```auto
# Example of `value` returned by database query.
value = [
  {"city": "Helsinki", "country": "Finland", "population": 635591},
  {"city": "Jakarta", "country": "Indonesia", "population": 10187595},
  {"city": "Madrid", "country": "Spain", "population": 3233527}
]

for row in range(len(value)):
	# Create a new dictionary item equal to the old one 
	# while popping the old one out of the dictionary.
	value[row]['capital'] = value[row].pop('city')

print value # Use this in the Script Console and delete in the Transform.
# return value	# Uncomment this in the Script Transform.

```

This returns

```auto
[
  {'country': 'Finland', 'capital': 'Helsinki', 'population': 635591}, 
  {'country': 'Indonesia', 'capital': 'Jakarta', 'population': 10187595}, 
  {'country': 'Spain', 'capital': 'Madrid', 'population': 3233527}
]

```

In general you shouldn’t have to do this. If the data is filling a table or chart you can specify the heading or caption on the actual component.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [February 11, 2022, 6:48pm UTC](https://forum.inductiveautomation.com/t/rename-the-column-of-a-dataset/56043/6 "2022-02-11T18:48:01Z")

</div>

> [@Transistor](#):
>
> Set your query to return **Document** format.  
> Add a script transform and modify the following code. (You can test it in the Script Console.

Assuming this is for perspective and a query binding is being used.

Changing the query output would not be available in vision, as far as I'm aware.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [February 11, 2022, 7:20pm UTC](https://forum.inductiveautomation.com/t/rename-the-column-of-a-dataset/56043/7 "2022-02-11T19:20:01Z")

</div>

Good point, Irose. I’m working 100% in Perspective.

---

<div class="post-metadata">

**Author:** ![jespinmartin1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jespinmartin1/32/57175_2.png) [@jespinmartin1](https://forum.inductiveautomation.com/u/jespinmartin1)\
**Post date:** [February 11, 2022, 7:44pm UTC](https://forum.inductiveautomation.com/t/rename-the-column-of-a-dataset/56043/8 "2022-02-11T19:44:37Z")

</div>

Another option, I haven’t test it

```auto
ds = your dataset
headers = system.dataset.getColumnHeaders(ds)
if ds.columnCount >= 4:
    headers[3] = "new name"
ds.setColumnNames​(headers)

```

Note this won’t work for BasicStreamingDataset

---

<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:** [February 11, 2022, 9:18pm UTC](https://forum.inductiveautomation.com/t/rename-the-column-of-a-dataset/56043/9 "2022-02-11T21:18:02Z")

</div>

`setColumnNames` is only implemented on [`BasicDataset`](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.14/com/inductiveautomation/ignition/common/BasicDataset.html#setColumnNames(java.util.List)), so it’s going to be more fragile than any of the other methods that work on _all_ datasets.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [April 29, 2022, 6:01pm UTC](https://forum.inductiveautomation.com/t/rename-the-column-of-a-dataset/56043/10 "2022-04-29T18:01:30Z")

</div>

I have the following code:

```auto
def getDailyDT_StatusData(lineNumber,day,returnSize = 2000):
	tpl = getDailyDT_TagPathsList(lineNumber)
	startTime = system.date.setTime(day,6,30,0)
	endTime = system.date.addDays(startTime,1)
	
	values = system.tag.queryTagHistory([path + '/Active' for path in tpl],startTime,endTime,includeBoundingValues = 1, returnSize = returnSize, returnFormat = 'Wide')
	names = system.dataset.getColumnHeaders(values)
	values.setColumnNames([names[0]] + [name.split('/',-1)[-2] for name in names[1:]])
	
	return values

```

This code is in a Project Script Library.

When I call it from the Script Console, it executes as expected.

When I call it from an Expression:

```auto
runScript('Daily_DT.getDailyDT_StatusData',0,{../TabContainer.props.currentTabIndex},{../Row_1/DateTimeInput.props.value})

```

I get an Error\_ExpressionEval(“Error executing script for runScript() expression:Daily\_DT.getDailyDT\_StatusData”)

Which honestly isn’t that helpful.

If I comment out the line with `setColumnNames` the script will execute. I’m just curious if there is some kind of scoping issue here, because that’s the only thing I can think of that is different.
