In this example, how do I write a Python script to accomplish this?

591
18
06-27-2018 05:40 AM
CharlesBanks2
New Contributor

In this example, how do I write a Python script to accomplish this result:

Site   ID

SIte A 0001

Site A 0001

SIte A 0001

Site A 0001

Site B 0002

SIte B 0002

Site B 0002

Site C 0003

SIte D 0004

0 Kudos
18 Replies
DanPatterson_Retired
MVP Esteemed Contributor

I am suspecting that there is more to it than that.

  • What is the purpose of the code?
  • Do any of the values exist before hand?
  • are you reading the file from somewhere?
  • What have you tried!
0 Kudos
CharlesBanks2
New Contributor

This is in connection with post: "Sequential Numbering Python Script for

Field Calculator in Arc 10.2" but a different sequence in the data.

Thanks,

Charles Banks

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

Well it can be done easily in more recent versions ( Table tools for ArcGIS PRO )

but perhaps if you included the link someone with an older version of ArcMap (or even 10.6) could have a look at what was posted there

0 Kudos
CharlesBanks2
New Contributor

The link is "

https://community.esri.com/thread/192672-sequential-numbering-python-script-for-field-calculator-in-...".

I don't have Pro and I would have to do this from Field Calc.

Thanks

Charles 

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

The code I posted is in that link... you just need to change the field name that contains the source classification

seq_count(!Test!)

in that thread's example the Site stuff was in a field called Test.  

You just need to do a field calculation with seq_count as the Code block and the seq_count(!YourFieldName!) as the expression.

Of course, you have to set the field calculator to the python parser

CharlesBanks2
New Contributor

This script does not produce the sequence above, it does work though!

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

It doesn't produce the exact sequence because... your data are different I suspect.

Perhaps you should show the data you are trying to produce a sequence for... or are you not following what the script does exactly?

0 Kudos
CharlesBanks2
New Contributor

This is a sample of what needs to be:

FIELDNEED TO BE
xxx_ 9999TUNK10_xxx_ 9999TUNK10_001
xxx_ 9999TUNK10_xxx_ 9999TUNK10_001
xxx_ 9999TUNK10_xxx_ 9999TUNK10_001
xxx_ 9999BANK12_xxx_ 9999BANK12_002
xxx_ 9999BANK17_xxx_ 9999BANK17_003
xxx_ 9999BANK1_xxx_ 9999BANK1_004
xxx_ 9999BANK20_xxx_ 9999BANK20_005
xxx_ 9999BANK20_xxx_ 9999BANK20_005
xxx_ 9999BANK20_xxx_ 9999BANK20_005
xxx_ 9999BANK30_xxx_ 9999BANK30_006
0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

did you substitute the !Test! name in the field calculator expression and try what I suggested?

perhaps you can take a screen grab of the field calculator dialog so we can see what you are doing

0 Kudos