Skip to main content
Solved

How to calculate distinct values within a list using Python?


dataninja
Forum|alt.badge.img

Can anyone show me how I can calculate the number of unique values within the list of each record using Python?

For example, what is the count of "Primary" or "Repair"?

I know that I can do this easily by exploding the list and go from there. But since I have over 1mil lists, I think the best way to do it is to take advantage of Python to improve performance. Thanks in advance!

Best answer by david_r

Have you looked at the ListHistogrammer? Would that get you what you need?

View original
Did this help you find an answer to your question?

2 replies

david_r
Evangelist
  • Best Answer
  • June 24, 2019

Have you looked at the ListHistogrammer? Would that get you what you need?


dataninja
Forum|alt.badge.img
  • Author
  • June 24, 2019
david_r wrote:

Have you looked at the ListHistogrammer? Would that get you what you need?

I will take a look at that transformer.

But this solved my problem:

 

import fme

from collections import Counter

import fmeobjects

my_list = feature.getAttribute('Business_Points_List{}.ODP Category')

for x in range(0,20):

print Counter(my_list).keys()[x]

print Counter(my_list).values()[x]

feature.setAttribute(Counter(my_list).keys()[x], Counter(my_list).values()[x])

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings