Select to view content in your preferred language

How to rearrange one field into two fields,

5697
20
Jump to solution
06-21-2015 02:15 AM
MajdoleenO_A__Awadallah
Frequent Contributor

I wonder if there is a way to rearrange one field into two fields instead of doing it manually, as shown in the attached,

rearrange.jpg

Any ideas,

Best,

Majdoleen

0 Kudos
20 Replies
DanPatterson_Retired
MVP Emeritus

Just add a field with a width wider than you need, the extra space is inconsequential in terms of file size.  So create the 2 text fields as I suggest and use the field calculation method I suggested earlier.  I would use Python particularly if you have no background in programming since it is the language that will be supported and VB is/will become a legacy language.

0 Kudos
MajdoleenO_A__Awadallah
Frequent Contributor

Thank you Dan, I tried using 200 field length and didn't work, sorry but I don't have any experience in writing the codes, I tried yours but didn't work too

0 Kudos
JayantaPoddar
MVP Esteemed Contributor

What is the length of "Facility_English"?



Think Location
0 Kudos
MajdoleenO_A__Awadallah
Frequent Contributor

50

0 Kudos
JayantaPoddar
MVP Esteemed Contributor

What version is the python? You can try installing the python that comes with your arcgis desktop.



Think Location
0 Kudos
MajdoleenO_A__Awadallah
Frequent Contributor

one thing, it is working good with facilityDescription_English ( !Facility_English!.split(":")[0]) but it fails to wirk with FacilityName_English (!Facility_English!.split(":")[1]) so I am not sure that the problem with the version,

I am using ArcGis 10.2.2

0 Kudos
JayantaPoddar
MVP Esteemed Contributor

Does all the values in field "Facility_English" contain a ":" (colon)?



Think Location
0 Kudos
DanPatterson_Retired
MVP Emeritus

It is the separator as I indicated in my earlier response

you only have to do it once if the separator is a " : " ,  in the field calculator, read the link I sent

If the separator is different then replace the ":" with a suitable replacement.  If there is no separator, then you will have to come up with your own rule.

From the help on string.split

Help on function split in module string:

split(s, sep=None, maxsplit=-1)
    split(s [,sep [,maxsplit]]) -> list of strings

Return a list of the words in the string s, using sep as the

    delimiter string.  If maxsplit is given, splits at no more than

    maxsplit places (resulting in at most maxsplit+1 words).  If sep

    is not specified or is None, any whitespace string is a separator.

If you have multiple delimiters then you will have to use the regular expression module ... re ..

as in

import re
re
.split('; |, ',str)

See this thread on Stack Overflow

Python: Split string with multiple delimiters - Stack Overflow

JayantaPoddar
MVP Esteemed Contributor

Majdoleen,

I could reproduce the error by replacing ":" in few values with other characters.

!Facility_English!.split(":")[0] works OK but !Facility_English!.split(":")[1] is giving error.

From the error snapshot, one can see a value (u"Parking") which doesn't have a colon sign, thus no value after a colon. Similar values will induce errors. Please use the split command with appropriate separator values for the selective records.



Think Location
SepheFox
Deactivated User

Yes, the problem is that there are some values that don't follow the same pattern. That is, as in the value "Parking", there is at least one values that doesn't contain a colon, and then a facility name. You could exclude these values by selecting by attributes, and then double clicking the original field name and inserting LIKE '%:%' after the field name in the expression window. This will select only the features that include the colon. Then go ahead and run the calculate field script. After that you can switch the selection, and calculate the remaining features, or edit them manually.