I have no idea how to use Python but I'm pretty sure there would be a way to do this, it's like using the MID query in excel. I'm using ArcGIS Pro and have a field for UK Postcodes, either in the format E4 9SU, DA12 7JS or DA1 7JS. I am trying to use the Field Calculator to delete the last three characters (4 including the space) so I will be left with either E4, DA12 or DA1
Is anyone able to help in writing the script? as I wouldn't even know where to start. The input field is called Match_Addr so after some research I'm assuming the input would be !Match_addr!
Would appreciate any help with this
Solved! Go to Solution.
Hi Emily Catt,
As you can see in the screen capture below I did take the content of the field POSTCODE to populate the field POSTCODE_SHORT with only the first part of the postal code.
Using Calculate Field, the very pythonic syntax to accomplish this is:
''.join(!POSTCODE!.split())[:-3]
So in your case that would be:
''.join(!Match_addr!.split())[:-3]
Please refer to this discussion for additional explanation: Python Remove last 3 characters of a string - Stack Overflow
Hope this helps,
Egge-Jan
Hi Emily Catt,
As you can see in the screen capture below I did take the content of the field POSTCODE to populate the field POSTCODE_SHORT with only the first part of the postal code.
Using Calculate Field, the very pythonic syntax to accomplish this is:
''.join(!POSTCODE!.split())[:-3]
So in your case that would be:
''.join(!Match_addr!.split())[:-3]
Please refer to this discussion for additional explanation: Python Remove last 3 characters of a string - Stack Overflow
Hope this helps,
Egge-Jan
Thank you for your speedy response Egge-Jan, worked like a charm! Thank you
Hi Emily Catt,
Sounds like your issue has been solved, doesn't it?
Would you please be so kind to mark your question as being answered? This will help the community in finding correct information.
Cheers,
Egge-Jan
Hi Joshua Bixby,
Joshua Bixby markeerde het antwoord van Emily Catt als juist
Why did you mark the "Thank you" as the correct answer, and not the actual answer I gave to the question?
Just curious 🙂
Egge-Jan
Sorry about that, clicked on the wrong link. I just updated it.