Skip to main content
Solved

How to calculate distinct values within a list using Python?

  • June 24, 2019
  • 2 replies
  • 37 views

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?

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

2 replies

david_r
Celebrity
  • 8394 replies
  • Best Answer
  • June 24, 2019

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


dataninja
Forum|alt.badge.img
  • Author
  • 44 replies
  • June 24, 2019

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])