-
Notifications
You must be signed in to change notification settings - Fork 1
/
Get distinct values of columns.py
39 lines (28 loc) · 1.41 KB
/
Get distinct values of columns.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#Run following ironpython just replace “Sample Data” with your tabel name and column name “Region” & "Item" with your column name for which you have to find distinctive values.
#get unique values from column (7.0)
from Spotfire.Dxp.Data import DataValueCursor
from Spotfire.Dxp.Data import IndexSet
tableName = 'Sample Data'
columnName = "Region"
columnName1 = "Item"
dt = Document.Data.Tables[tableName]
cursor = DataValueCursor.Create[str](dt.Columns[columnName])
distinctRows = dt.GetDistinctRows(None,cursor) #none param to grab them by the all
#distinctRows = dt.GetDistinctRows(IndexSet(dt.RowCount,True),cursor) #...or an indexset with all true to get them all.
#get uniques
vals = []
distinctRows.Reset()
while distinctRows.MoveNext():vals.append(cursor.CurrentValue)
#show results
print vals
#The following code is just a copy paste of above code so as to get distinct values for two columns concurrently, Obviously its not necessary at all
dt = Document.Data.Tables[tableName]
cursor = DataValueCursor.Create[str](dt.Columns[columnName1])
distinctRows = dt.GetDistinctRows(None,cursor) #none param to grab them by the all
#distinctRows = dt.GetDistinctRows(IndexSet(dt.RowCount,True),cursor) #...or an indexset with all true to get them all.
#get uniques
vals = []
distinctRows.Reset()
while distinctRows.MoveNext():vals.append(cursor.CurrentValue)
#show results
print vals