[英]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.