Jump to content
  • Replace specific values of a Data Table column in Spotfire® using IronPython


    Sample code to replace values in a column of a Data Table

    Introduction

    This example provides a sample code to replace values in a column of a Data Table

    Code Sample

    # Copyright © 2017. TIBCO Software Inc. Licensed under TIBCO BSD-style license.
    
    from Spotfire.Dxp.Data import *
    from Spotfire.Dxp.Data.Transformations import *
    
    dataOperation = dataTable.GenerateSourceView().OperationsSupportingTransformations[0];
    transformations = dataOperation.GetTransformations();
    
    #clear all transformations on this dataTable if needed
    dataOperation.ReplaceTransformations("")
    
    #Replace Values Transformation
    column = DataColumnSignature("Year",DataType.Integer);
    t=transformations.Add(ReplaceValuesTransformation(column, 0, 2018))
    dataOperation.ReplaceTransformations(transformations)
    
    #Replace specific value Transformation
    column = DataColumnSignature("Severity",DataType.String);
    row_id_cols=[DataColumnSignature("ID",DataType.Integer)]
    row_id_col_values = [7]
    transformations.Add(ReplaceSpecificValueTransformation(column, "Med","Medium",row_id_cols, row_id_col_values,True))
    dataOperation.ReplaceTransformations(transformations);
    
    
    #dataTable - Table script parameter in which the value needs to be replaced
     

    References

    License:  TIBCO BSD-Style License


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...