Gets simple statistics from ZenTable

Everything OAD-related that won't fit in the other categories: share general aspects of macro programming and discuss the OAD environment
Post Reply
user-6033
Posts: 89
Joined: Thu Jan 01, 1970 1:00 am

Gets simple statistics from ZenTable

Post by user-6033 »

Hi,

Simple statistics like sum, stDev, var, avg, max, min and count can be easily extracted from the tables by adding one extra column for each statistical parameteter of interest and then use the ZenTable.Columns[index].Expression method, see example below. The new column will contain the same aggregated value on each row. Since this procedure needs to be repeated for each feature columnName it can end up with rather messy large tables. It would then be better to create a child table for each feature column where the child contains the statistical parameters of interest, which now also only will occupy one row. However, for that one needs to go to System.Data and use the DataRelation class, create the relation and add it to dataset.tables, which in turn contains the added parent table table and child table. Is there a way to cast the ZenTable to a DataTable, since the dataset.tables.add does not accept ZenTable type?


#myZenTable contains a column with ColumnName "area"
myZenTable.Columns.Add(“average area”)
avgareainx = myZenTable.Columns.indexof("average area")
myZenTable.Columns[avgareainx].Expression = “Avg(area)”

#Each row in column "average area" will now contain the average value of all area values column will now contains

Kind regards
Fredrik Olsson
steve diaz
Posts: 1
Joined: Mon Dec 18, 2023 9:41 am

Re: Gets simple statistics from ZenTable

Post by steve diaz »

Regarding your question, you can create a DataTable and copy data from ZenTable manually. Here's a quick example:
myDataTable = DataTable()

for column in myZenTable.Columns:
myDataTable.Columns.Add(column.ColumnName, type(column.DataType))

for row in myZenTable.Rows:
newRow = myDataTable.NewRow()
for column in myZenTable.Columns:
newRow[column.ColumnName] = row[column]
myDataTable.Rows.Add(newRow)
Now, you can use myDataTable with DataSet.Tables.Add.
Post Reply