[英]Spotfire: average of a column with ironpython, using expression
我希望在 Spotfire 中的表上执行一些基本的统计功能。 例如:我想计算列 [A] 中所有值的平均值,并且我需要将此值作为 IronPython 中的变量。
我可以读取列中的所有值,将它们相加并在 IronPython 中完全计算平均值,但由于我还想使用其他 Spotfire 的统计函数,我希望我可以以某种方式调用 Spotfire API 并使用表达式(以与创建计算列)。 像这样的东西:
expr = "Avg([{col}])".format(col = colName)
现在我需要一种方法来调用这个表达式并将结果存储在一个变量中以供以后使用。
在伪代码中:
colName = "Weight"
value = API.SomeFunction(expr)
如果可能的话,我将不胜感激任何提示和信息。
以防其他人可能从中受益。 到目前为止,我发现的最佳近似值是这样的(代码的相关摘录):
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
我为每个表达式组合创建计算列,我需要它的值。 然后我读取计算列的第一个值(所有值都相同):
def getFirstFloatValue(table, colName):
cursor = DataValueCursor.Create[float](table.Columns[colName])
for row in table.GetRows(cursor):
return cursor.CurrentValue
return
我使用值val
然后删除列。
我相信可能有更好的解决方案,但无论如何我都会发布这个,因为其他人可能会从这个解决方案中受益。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.