简体   繁体   English

Spotfire:使用ironpython的列的平均值,使用表达式

[英]Spotfire: average of a column with ironpython, using expression

I wish to perform some basic statistic functions on my table in Spotfire.我希望在 Spotfire 中的表上执行一些基本的统计功能。 For example: I want to calculate average of all values in column [A] and I need to have this value as variable in IronPython.例如:我想计算列 [A] 中所有值的平均值,并且我需要将此值作为 IronPython 中的变量。

I can read all values in the column, sum them and calculate the average completely in IronPython, but since I would also like to use other Spotfire's statistical functions, I expected that I could somehow call Spotfire API and use expression (in the same manner that calculated column is created).我可以读取列中的所有值,将它们相加并在 IronPython 中完全计算平均值,但由于我还想使用其他 Spotfire 的统计函数,我希望我可以以某种方式调用 Spotfire API 并使用表达式(以与创建计算列)。 Something like this:像这样的东西:

expr = "Avg([{col}])".format(col = colName)

Now I would need a way to call this expression and store the result in a variable to use later.现在我需要一种方法来调用这个表达式并将结果存储在一个变量中以供以后使用。

In pseudo code:在伪代码中:

colName = "Weight"
value = API.SomeFunction(expr)

I would be grateful for any hints and also for information if this is possible at all.如果可能的话,我将不胜感激任何提示和信息。

In case someone else might benefit from this.以防其他人可能从中受益。 The best approximation that I found so far is this (relevant excerpt from the code):到目前为止,我发现的最佳近似值是这样的(代码的相关摘录):

row6 = "Srel"
for col in SampleColumns:
    colExp = "StdDev([{col}]) / Avg([{col}]) * 100".format(col = col)
    colName = col + colExp[0:colExp.find("(")]
    sT.Columns.AddCalculatedColumn(colName, colExp)
    val = getFirstFloatValue(sT, colName)
    row6 += TAB + str(val)
    sT.Columns.Remove(colName)
row6 += EOL

I create calculated column for each combination of the expression an column, that I need the value of.我为每个表达式组合创建计算列,我需要它的值。 Then I read the first value of calculated column (all values are the same):然后我读取计算列的第一个值(所有值都相同):

def getFirstFloatValue(table, colName):
    cursor = DataValueCursor.Create[float](table.Columns[colName])
    for row in table.GetRows(cursor):
        return cursor.CurrentValue
    return 

I use the value val and then delete column.我使用值val然后删除列。

I believe there might be better solutions, but I am posting this anyway, because someone else might benefit from this solution.我相信可能有更好的解决方案,但无论如何我都会发布这个,因为其他人可能会从这个解决方案中受益。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM