Spotfire IronPython 替换数据表值

问题描述 投票:0回答:1

在 Spotfire 中,我尝试将字符串写入表列的标记行中。

from Spotfire.Dxp.Data import *

dataTable = Document.Data.Tables["myTable"]
cursor = DataValueCursor.CreateFormatted(dataTable.Columns["myColumn"])
markings = Document.ActiveMarkingSelectionReference.GetSelection(dataTable)

some_string = "some_string"

for row in dataTable.GetRows(markings.AsIndexSet(),cursor):
    cursor.CurrentValue = some_string

根据这个问题,应该可以在光标位置写入表格。 但是,我收到错误

AttributeError: can't assign to read-only property CurrentValue of type 'DataColumnValueCursor[str]'

我做错了什么?

ironpython spotfire
1个回答
0
投票

您正在检索的光标值确实是只读的。您所指的示例似乎正在替换生成计算列的表达式,而不是行中的特定值。

替换具体值比较复杂。当您在没有脚本的情况下执行此操作时,双击一行中的一列,然后对话框会询问您是否要替换具有该值的所有行,还是仅替换特定行。如果要替换特定行,则必须提供包含唯一行标识符的列。您必须双击要更改的每一行,然后重复该操作。因此,在数据画布中,您将为每一行添加一个转换操作。

与 Iron Python 类似,对于每一行,您都必须标识一个 id 列并添加一个转换来替换原始值。

以下脚本对我有用(以 iris 数据集为例,加上我使用表达式 RowId()) 创建的计算“ID”列)。

我还需要确保将转换附加到现有转换(否则,就我而言,它会在创建 ID 列之前尝试应用转换)。

from Spotfire.Dxp.Data import *
from Spotfire.Dxp.Data.Transformations import *

dataTable = Document.Data.Tables["iris"]
column=dataTable.Columns["Species"]
id_column=dataTable.Columns["ID"]

cursor = DataValueCursor.CreateFormatted(column)
id_cursor = DataValueCursor.CreateFormatted(id_column)
markings = Document.ActiveMarkingSelectionReference.GetSelection(dataTable)

data_operations = 
dataTable.GenerateSourceView().OperationsSupportingTransformations
last_data_operation=data_operations[len(data_operations)-1]
transformations = last_data_operation.GetTransformations()

col_signature = DataColumnSignature(column.Name,DataType.String)
id_col_signature = DataColumnSignature(id_column.Name,DataType.Integer)

some_string = "some_string"

for row in dataTable.GetRows(markings.AsIndexSet(),cursor,id_cursor):
    value=cursor.CurrentValue
    id_value=int(id_cursor.CurrentValue)
    transformations.Add(ReplaceSpecificValueTransformation(col_signature, 
value,some_string,\
        [id_col_signature], [id_value],True))


last_data_operation.ReplaceTransformations(transformations)
© www.soinside.com 2019 - 2024. All rights reserved.