I wonder if there is a way to rearrange one field into two fields instead of doing it manually, as shown in the attached,
Any ideas,
Best,
Majdoleen
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.
yes you are right, thank you all really appreciate, it os working fine now.
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.
Hi Jayanta,
both have the same length= 50
What is the length of the text field "FacilityName_English"? Add a text field with a length long enough to contain the longest split string.
Thank you Dan Patterson and Jayanta Poddar ,really appreciate , it is working perfect with first expression but with the second one it fails, I couldn't figure out why it fails, and gave the error bellow.
Hi Majdoleen,
As I can see from the snapshot, you have 6107 records (not fields). So the expressions given by Dan Patterson should work for all the records at one go.
Taking your data into consideration, let me put down the expressions once again.
Make sure none of the records are selected.
My Assumption: You are spliting the text with ":" (colon) separator.
Use Field Calculator for FacilityDescription_English
Parser: Python
Expression=
!Facility_English!.split(":")[0]
Use Field Calculator for FacilityName_English
!Facility_English!.split(":")[1]
Thank you Dan, It is working but the challenge here that I have to type the field name 6000 times, each field has different value.
It does it for the whole field at once in the Field Calculator have a read through the section...it is much like a spreadsheet
Thank you Dan, but do I have to do this for all the values, we are talking about more than 6000 values!!, if it is possible, could you please send me more details using screen shots ,
Open your table and add two fields and add 2 text (string) fields if you already haven't done so.
You python's 'split' function to cut the field into 2 based upon a common factor... that you have a ':' in the same place
We will denote your field as variable f.
Make the first field you want to add data to and we will get the 'Townhall' part of the string into it
Select the python parser, double click on your field name containing the original data and then append ' .split(":")[0] to the fields name so your expression should look like
"your original field".split(":")[0]
hit enter and the results should be there. repeat on the 2nd field using
"your original field".split(":")[1]
and you should have the facility types.
In pure python with a field named 'f' this would look like this
>>> f = "Townhall:Municipal Building"
>>>
>>> a = f.split(":")[0]
>>> b = f.split(":")[1]
>>> a
'Townhall'
>>> b
'Municipal Building'
Los miembros registrados pueden publicar, seguir actualizaciones y más. ¿Nuevo aquí? Regístrate gratis.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.