# Python dataset group by date

**URL:** <https://forum.inductiveautomation.com/t/python-dataset-group-by-date/44151>\
**Category:** Ignition\
**Tags:** ignition80, perspective\
**Created:** [March 5, 2021, 2:41pm UTC](https://forum.inductiveautomation.com/t/python-dataset-group-by-date/44151 "2021-03-05T14:41:02Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [March 5, 2021, 2:41pm UTC](https://forum.inductiveautomation.com/t/python-dataset-group-by-date/44151/1 "2021-03-05T14:41:03Z")

</div>

Hi

In perspective I get dataset from MySQL db and put it in charts and tables in object format.  
To avoid to get another SQL query, I would like to group by day, month, year my dataset variable with a script transform.  
Is it possible in python ?

Thanks,

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 5, 2021, 4:02pm UTC](https://forum.inductiveautomation.com/t/python-dataset-group-by-date/44151/2 "2021-03-05T16:02:09Z")

</div>

The [Simulation Aids Module](https://inductiveautomation.com/moduleshowcase/module/automation-professionals-llc-simulation-aids) might help. You can use psuedoSQL on a dataset with its view() function.

---

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [March 8, 2021, 10:56am UTC](https://forum.inductiveautomation.com/t/python-dataset-group-by-date/44151/3 "2021-03-08T10:56:38Z")

</div>

Thanks,

Do you have an example with a group by statement ?  
Mydataset :

```auto
[{'t_stamp':'2021-01-01 00:00:00','value':59}, {'t_stamp':'2021-01-01 01:00:00','value':52}, ...]

```

SQL query in view() :

```auto
SELECT DATE(t_stamp) as t_stamp, sum(value) as value GROUP BY DATE(t_stamp)

```

I tried expression but it doesn’t work :

```auto
view('select date(t_stamp),sum(value) as value group by date(t_stamp)',{this.props.dataSources.example})

```

---

<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:** [March 8, 2021, 11:04am UTC](https://forum.inductiveautomation.com/t/python-dataset-group-by-date/44151/4 "2021-03-08T11:04:55Z")

</div>

There’s no date() function. Just use the t\_stamp column if it already has zeros for hour, minute, second.

---

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [March 8, 2021, 11:33am UTC](https://forum.inductiveautomation.com/t/python-dataset-group-by-date/44151/5 "2021-03-08T11:33:24Z")

</div>

```auto
view('select t_stamp,sum(value) as value group by t_stamp',{this.props.dataSources.example})

```

It still not working. I think SimulAids Module can’t responds to my needs ==\> just group a dataset by day

---

<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:** [March 8, 2021, 4:30pm UTC](https://forum.inductiveautomation.com/t/python-dataset-group-by-date/44151/6 "2021-03-08T16:30:23Z")

</div>

Your ‘dataset’ looks like a list of dictionaries. view() needs an actual Dataset.

---

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [March 11, 2021, 3:59pm UTC](https://forum.inductiveautomation.com/t/python-dataset-group-by-date/44151/7 "2021-03-11T15:59:11Z")

</div>

It seems pandas library can group data but it can’t be installed in ignition. Is it true ?

---

<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:** [March 11, 2021, 4:02pm UTC](https://forum.inductiveautomation.com/t/python-dataset-group-by-date/44151/8 "2021-03-11T16:02:12Z")

</div>

Yes, you can not use any python library which has ‘C python’ dependencies.

---

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [March 11, 2021, 4:25pm UTC](https://forum.inductiveautomation.com/t/python-dataset-group-by-date/44151/9 "2021-03-11T16:25:14Z")

</div>

Is there any other solution to aggregate data (grouping like sql) with python ?😭

---

<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:** [March 11, 2021, 4:32pm UTC](https://forum.inductiveautomation.com/t/python-dataset-group-by-date/44151/10 "2021-03-11T16:32:52Z")

</div>

> [@flavien](#):
>
> I get dataset from MySQL db and put it in charts and tables in object format.

Just get the data in _dataset_ format in some custom property. Transform it to object format where you are currently using it, and use the dataset for the view() operation.

---

<div class="post-metadata">

**Author:** ![Italo\_Araujo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/italo_araujo/32/42108_2.png) [@Italo\_Araujo](https://forum.inductiveautomation.com/u/Italo_Araujo)\
**Post date:** [December 27, 2022, 3:59pm UTC](https://forum.inductiveautomation.com/t/python-dataset-group-by-date/44151/11 "2022-12-27T15:59:09Z")

</div>

> [@flavien](#):
>
> It still not working. I think SimulAids Module can’t responds to my needs ==\> just group a dataset by day

I had the same question, my topic might be able to help you!

[https://forum.inductiveautomation.com/t/replace-row-values-in-a-dataset/67987](https://forum.inductiveautomation.com/t/replace-row-values-in-a-dataset/67987)
