I need to copy only the numerical value and paste it in a new column
using the field calculator
import re def extract_number(txt): numbers = re.findall(r"\d+", txt) if not numbers: return None return numbers[0]
The Name column looks like a string representation of a Python tuple containing a str and int., so using Python eval built-in should work:
>>> a = "('tienda la samaritana', 100)" >>> eval(a)[1] 100 >>>
Does it matter which coding language you use? Python
Is the "Name" column consistently formatted? string
Will there ever be numbers in the first part of the string? it´s Possible
If there are no other numbers as in the examples you have shown...
a = "('tienda la samaritana', 100)" b = int("".join([i for i in a if i.isnumeric()])) b 100
as a field calculator expression replace 'a' with !YourFieldName! and don't assign it to b,
Does it matter which coding language you use?
Is the "Name" column consistently formatted?
Will there ever be numbers in the first part of the string?
If the number is always at the end of the string like that, you could use Split, Left, and Count to accomplish this in Arcade.
var test_string = "('tienda la samaritana', 100)" var split_string = Split(test_string, ',') Console(split_string) var number_portion = split_string[-1] Console(number_portion) var the_number = Left(number_portion, Count(number_portion) - 1) Console(the_number) return Number(the_number)
Here's the console:
["('tienda la samaritana'"," 100)"] 100) 100
And here's the output:
If you prefer to use Python, you could probably get this done with a regular expression.
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.