1

I have few data tables in spotfire. But i need to refer column in specific table (which is not current Active reference table) using iron python scripting. And also I would like to print unique values in a column.

EX : I have a property control with 50 values and in filter panel as check box when user selects a value from property control the check box filter to check that value and has to uncheck remaining vales lly when user selects none it has to uncheck all the values in that check box filter.

sofuser9
  • 219
  • 3
  • 14

2 Answers2

4

You can get the values from a column with the below script. The control is just used if you have a ton of data. You can remove it if you'd like.

from Spotfire.Dxp.Data import *

tableName='your_table_name'
columnToFetch='your_column_name'
activeTable=Document.Data.Tables[tableName]
rowCount = activeTable.RowCount
rowsToInclude = IndexSet(rowCount,True)
cursor1 = DataValueCursor.CreateFormatted(activeTable.Columns[columnToFetch])
ctr1 = 0
for row in activeTable.GetRows(rowsToInclude,cursor1):
    rowIndex = row.Index
    val1 = cursor1.CurrentValue
    print val1
    ctr1 = ctr1 + 1
    if (ctr1 == 5):
        break

Credit TechGoje

S3S
  • 24,809
  • 5
  • 26
  • 45
  • Thanks scsimon with this script i can able to print all the values [Even duplicates] in a column,but is there any way to print Unique values from a specific column – sofuser9 Sep 07 '16 at 03:21
  • @Rama you'll have to store it in a unique array. Hope this helped you. It's 99% no? A little research in the API would finish it up – S3S Sep 08 '16 at 01:03
  • 1
    @rama you also haven't up voted or accepted a single answer on your previous questions. I would encourage you to revisit those and upvote helpful answers and accept those that are correct. Many stackoverflow contributors may ignore your questions if your trend continues to not reward supporters. Food for thought mate. – S3S Sep 08 '16 at 01:08
1

The script from this post can be used to get unique values from the data table column. It works as below -

  1. Creates a cursor to column rowCount = activeTable.RowCount rowsToInclude = IndexSet(rowCount,True) cursor = DataValueCursor.CreateFormatted(activeTable.Columns[columnToFetch])
  2. Use a dictionary to store values, and then printing keys.

    uc=dict()

  3. Add Value to the dictionary by traversing through cursor for row in activeTable.GetRows(rowsToInclude,cursor): rowIndex = row.Index val = cursor.CurrentValue uc.update({val:ctrl})

  4. Retrieve values from dictionary

    for key in uc: print key