How to get the count of the Non repeated values in a specific column inside a table?
i can only get all table count by using ---> value.getRowCount()
I enjoy using ds.getColumnAsList() (ds is a dataset) and then the python set() constructor to get unique values in a column. You can count the number of unique values with len() after that. If what you are looking for is more complicated then that, you would need to write a specific function.
len(set(ds.getColumnAsList(ds.getColumnIndex("column_name"))))
3 Likes
In my opinion, a custom script will do the job. A sample script to extract the values will be as follow:
lst = self.getSibling("Table").props.data
element_count = {}
for element in lst:
element_count[int(element['population'])] = element_count.get(int(element['population']), 0) + 1
# Count non-duplicate values
non_duplicates_count = sum(1 for count in element_count.values() if count == 1)
self.getSibling("Label").props.text = non_duplicates_count
The first line is extracting the data from the table, and the last line is showing the non-duplicate count in a label text. Please feel free to change these lines as per your visual.
My sample visual for the script testing looks like this:
Thanks.
Thanks alot