Label Expression python code to count repeating values

3397
2
12-03-2015 06:14 PM
pramodmishra
New Contributor

Hello,

I am facing challenges on python code to label the repeating numbers in attribute table. Please see below image

I want to use label expression to plot A(2), B(2),C(3) and D(1). Inside the bracket are count number. I will appreciate for the code, python prefer but can be vb script or anything else that works. THank you. And one more thing feature class sits in geodatabse and have to make connection.

0 Kudos
2 Replies
FreddieGibson
Occasional Contributor III

I don't believe that this is going to be easily possible within a label expression because it'd require that you scan the entire table to get the counts and then come back to the row where you needed to generate the label? I'd assume that you could probably add logic to the label expression, but this would probably only slow down the map rendering to the point it'd be unusable because you'd be crawling the entire feature class for each label rendered every time you refreshed the map.

Would it be possible for you to add a field to your data where you could calculate this value and then you could label based on that field?

LukeSturtevant
Occasional Contributor III

What type of feature class is this? Are you looking to just have one label per feature? You Dissolve—Data Management toolbox | ArcGIS for Desktop on the Letter ID field and use the statistics type 'COUNT' option parameter on the ID field. After you do the dissolve you can label it using an expression similar to this :

[Label]  +"("+ [COUNT_ID] +")"