Splitting string ID code into various partsSelect polygons contained inside a polygon and assign IDHow to...
How to deal with a cynical class?
Could the Saturn V actually have launched astronauts around Venus?
What are the possible solutions of the given equation?
How do I hide Chekhov's Gun?
Does this AnyDice function accurately calculate the number of ogres you make unconcious with three 4th-level castings of Sleep?
Good allowance savings plan?
Why is "das Weib" grammatically neuter?
I need to drive a 7/16" nut but am unsure how to use the socket I bought for my screwdriver
Is having access to past exams cheating and, if yes, could it be proven just by a good grade?
Meaning of "SEVERA INDEOVI VAS" from 3rd Century slab
Can hydraulic brake levers get hot when brakes overheat?
In-house repeater?
Theorems like the Lovász Local Lemma?
Co-worker team leader wants to inject his friend's awful software into our development. What should I say to our common boss?
Informing my boss about remarks from a nasty colleague
Science-fiction short story where space navy wanted hospital ships and settlers had guns mounted everywhere
How to answer questions about my characters?
Validating user input
Russian cases: A few examples, I'm really confused
Know when to turn notes upside-down(eighth notes, sixteen notes, etc.)
How to generate globally unique ids for different tables of the same database?
Be in awe of my brilliance!
Employee lack of ownership
At what level can a dragon innately cast its spells?
Splitting string ID code into various parts
Select polygons contained inside a polygon and assign IDHow to place points along a line in a specific offset using python / arcpy?Help with formatting ArcGIS text elements with PythonAssigning a vector to a field in feature class (UpdateCursor)Splitting string column into 2 columns in Python?Find the first occurrence of any letter in an alphanumeric stringHow can I convert Bing's “quadtree” tile addresses to ZXY tile addresses in Python?Address Prefix Strip Using PythonPython code help for ArcGIS Field calculator?Overlay two linestring objects in geopandas, accounting for the attributes
I have a series of identification codes that I need to split out. The format of these codes is [region(letter)][district(number)] - [place(number)][subdistrict(letter)]. An example of a some codes include S22-201, TT100-12, and V6-1B. Often there is no subdistrict, and all points fall within the same larger district (so no As or Cs or whatever at the end of the string.
I do not know Python very well, but have done by best to search around for relevant code to accomplish this, but have had very little luck. I can do parts of it, like splitting at the hyphen...
!Original_ID!.split('-')[0]
and then extracting the district...
!Split_ID![1:3]
But it seems like two steps for this is unnecessary, and only works when I know the specific number of characters in the string, which isn't realistic for a large data set. I'd like to be able to grab each peace at once: letters on the left of the hyphen, numbers on the left of the hyphen, numbers on the right of the hyphen, and letters (if any) on the right of the hyphen. I'd need the numeric fields to be integers (or I guess possibly floats in some rare cases maybe).
python arcmap field-calculator
New contributor
add a comment |
I have a series of identification codes that I need to split out. The format of these codes is [region(letter)][district(number)] - [place(number)][subdistrict(letter)]. An example of a some codes include S22-201, TT100-12, and V6-1B. Often there is no subdistrict, and all points fall within the same larger district (so no As or Cs or whatever at the end of the string.
I do not know Python very well, but have done by best to search around for relevant code to accomplish this, but have had very little luck. I can do parts of it, like splitting at the hyphen...
!Original_ID!.split('-')[0]
and then extracting the district...
!Split_ID![1:3]
But it seems like two steps for this is unnecessary, and only works when I know the specific number of characters in the string, which isn't realistic for a large data set. I'd like to be able to grab each peace at once: letters on the left of the hyphen, numbers on the left of the hyphen, numbers on the right of the hyphen, and letters (if any) on the right of the hyphen. I'd need the numeric fields to be integers (or I guess possibly floats in some rare cases maybe).
python arcmap field-calculator
New contributor
add a comment |
I have a series of identification codes that I need to split out. The format of these codes is [region(letter)][district(number)] - [place(number)][subdistrict(letter)]. An example of a some codes include S22-201, TT100-12, and V6-1B. Often there is no subdistrict, and all points fall within the same larger district (so no As or Cs or whatever at the end of the string.
I do not know Python very well, but have done by best to search around for relevant code to accomplish this, but have had very little luck. I can do parts of it, like splitting at the hyphen...
!Original_ID!.split('-')[0]
and then extracting the district...
!Split_ID![1:3]
But it seems like two steps for this is unnecessary, and only works when I know the specific number of characters in the string, which isn't realistic for a large data set. I'd like to be able to grab each peace at once: letters on the left of the hyphen, numbers on the left of the hyphen, numbers on the right of the hyphen, and letters (if any) on the right of the hyphen. I'd need the numeric fields to be integers (or I guess possibly floats in some rare cases maybe).
python arcmap field-calculator
New contributor
I have a series of identification codes that I need to split out. The format of these codes is [region(letter)][district(number)] - [place(number)][subdistrict(letter)]. An example of a some codes include S22-201, TT100-12, and V6-1B. Often there is no subdistrict, and all points fall within the same larger district (so no As or Cs or whatever at the end of the string.
I do not know Python very well, but have done by best to search around for relevant code to accomplish this, but have had very little luck. I can do parts of it, like splitting at the hyphen...
!Original_ID!.split('-')[0]
and then extracting the district...
!Split_ID![1:3]
But it seems like two steps for this is unnecessary, and only works when I know the specific number of characters in the string, which isn't realistic for a large data set. I'd like to be able to grab each peace at once: letters on the left of the hyphen, numbers on the left of the hyphen, numbers on the right of the hyphen, and letters (if any) on the right of the hyphen. I'd need the numeric fields to be integers (or I guess possibly floats in some rare cases maybe).
python arcmap field-calculator
python arcmap field-calculator
New contributor
New contributor
edited 44 secs ago
Vince
14.7k32749
14.7k32749
New contributor
asked 24 mins ago
vce500vce500
11
11
New contributor
New contributor
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You're not going to be able to calculate two fields in one go.. though you can split it up into two calcs. I would do this with an update cursor:
with arcpy.da.UpdateCursor(YourFeatureClass,['Original_ID','District','Split_ID']) as uCur:
for sRow in uCur:
OrigID = sRow[0].split('-')[0] # first element in the Original_ID
charRng = range(len(OrigID)) # a range to iterate over
Chars = ''
Numbers = ''
for Idx in charRng:
if OrigID[Idx].isnumeric():
Numbers += OrigID[Idx]
else:
chars += OrigID[Idx]
sRow[1] = float(Numbers)
sRow[2] = Chars
uCur.updateRow(sRow)
This shows how to break up a string into numbers and not numbers and put the values into a row, it should give you some ideas where to start from.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "79"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
vce500 is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f315591%2fsplitting-string-id-code-into-various-parts%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You're not going to be able to calculate two fields in one go.. though you can split it up into two calcs. I would do this with an update cursor:
with arcpy.da.UpdateCursor(YourFeatureClass,['Original_ID','District','Split_ID']) as uCur:
for sRow in uCur:
OrigID = sRow[0].split('-')[0] # first element in the Original_ID
charRng = range(len(OrigID)) # a range to iterate over
Chars = ''
Numbers = ''
for Idx in charRng:
if OrigID[Idx].isnumeric():
Numbers += OrigID[Idx]
else:
chars += OrigID[Idx]
sRow[1] = float(Numbers)
sRow[2] = Chars
uCur.updateRow(sRow)
This shows how to break up a string into numbers and not numbers and put the values into a row, it should give you some ideas where to start from.
add a comment |
You're not going to be able to calculate two fields in one go.. though you can split it up into two calcs. I would do this with an update cursor:
with arcpy.da.UpdateCursor(YourFeatureClass,['Original_ID','District','Split_ID']) as uCur:
for sRow in uCur:
OrigID = sRow[0].split('-')[0] # first element in the Original_ID
charRng = range(len(OrigID)) # a range to iterate over
Chars = ''
Numbers = ''
for Idx in charRng:
if OrigID[Idx].isnumeric():
Numbers += OrigID[Idx]
else:
chars += OrigID[Idx]
sRow[1] = float(Numbers)
sRow[2] = Chars
uCur.updateRow(sRow)
This shows how to break up a string into numbers and not numbers and put the values into a row, it should give you some ideas where to start from.
add a comment |
You're not going to be able to calculate two fields in one go.. though you can split it up into two calcs. I would do this with an update cursor:
with arcpy.da.UpdateCursor(YourFeatureClass,['Original_ID','District','Split_ID']) as uCur:
for sRow in uCur:
OrigID = sRow[0].split('-')[0] # first element in the Original_ID
charRng = range(len(OrigID)) # a range to iterate over
Chars = ''
Numbers = ''
for Idx in charRng:
if OrigID[Idx].isnumeric():
Numbers += OrigID[Idx]
else:
chars += OrigID[Idx]
sRow[1] = float(Numbers)
sRow[2] = Chars
uCur.updateRow(sRow)
This shows how to break up a string into numbers and not numbers and put the values into a row, it should give you some ideas where to start from.
You're not going to be able to calculate two fields in one go.. though you can split it up into two calcs. I would do this with an update cursor:
with arcpy.da.UpdateCursor(YourFeatureClass,['Original_ID','District','Split_ID']) as uCur:
for sRow in uCur:
OrigID = sRow[0].split('-')[0] # first element in the Original_ID
charRng = range(len(OrigID)) # a range to iterate over
Chars = ''
Numbers = ''
for Idx in charRng:
if OrigID[Idx].isnumeric():
Numbers += OrigID[Idx]
else:
chars += OrigID[Idx]
sRow[1] = float(Numbers)
sRow[2] = Chars
uCur.updateRow(sRow)
This shows how to break up a string into numbers and not numbers and put the values into a row, it should give you some ideas where to start from.
answered 32 secs ago
Michael StimsonMichael Stimson
21.6k22360
21.6k22360
add a comment |
add a comment |
vce500 is a new contributor. Be nice, and check out our Code of Conduct.
vce500 is a new contributor. Be nice, and check out our Code of Conduct.
vce500 is a new contributor. Be nice, and check out our Code of Conduct.
vce500 is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Geographic Information Systems Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f315591%2fsplitting-string-id-code-into-various-parts%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown