Select to view content in your preferred language

Split alphanumeric field into two fields

2274
1
10-11-2013 06:31 AM
MikeScott
Deactivated User
I have an address table that has the house number and street name in the same field.  I need to separate the number and text and put into 2 different fields.  Any way to do in field Calculator?  Examples of existing data in the single field:

1919 LAWSON RD
919 PRINCE CHARLES LN
1437-1455 PAYNE RD
407 N BRAINTREE DR
Tags (2)
0 Kudos
1 Reply
T__WayneWhitley
Honored Contributor
...could use python's .split(' ') but then what do you plan to do with address ranges?
>>> addresses = ['1919 LAWSON RD','919 PRINCE CHARLES LN','1437-1455 PAYNE RD','407 N BRAINTREE DR']
>>> for address in addresses:
 address.split(' ')

 
['1919', 'LAWSON', 'RD']
['919', 'PRINCE', 'CHARLES', 'LN']
['1437-1455', 'PAYNE', 'RD']
['407', 'N', 'BRAINTREE', 'DR']
>>> 
>>> for address in addresses:
 address.split(' ', 1)

 
['1919', 'LAWSON RD']
['919', 'PRINCE CHARLES LN']
['1437-1455', 'PAYNE RD']
['407', 'N BRAINTREE DR']
>>> 



...so if that (above) is good enough for you, then it's a single statement:
arcpy.CalculateField_management("your fc or tbl", "your num add fld", '!your orig add fld!.split(" ")[0]', "PYTHON_9.3")



...and of course for the alternate field for the remaining text, run a 2nd execution (by the way, with an updatecursor you could run a single execution to write both fields)---
arcpy.CalculateField_management("your fc or tbl", "your txt add fld", '!your orig add fld!.split(" ")[1]', "PYTHON_9.3")
0 Kudos