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
Solved! Go to Solution.
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.
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'
>>>
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 ,
Best,
Majdoleen
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, It is working but the challenge here that I have to type the field name 6000 times, each field has different value.
you only have to do it once if the separator is a " : " , in the field calculator, read the link I sent
If you have thousands of different field names ... not different rows... then you need to script it... but you have not provided any information as to were these fields reside how one can generalize the field names etc etc. In any event, what I sent is how you do it simply to calculate valeus for a field given the structure in the field that you provided. You will have to provide more information or you will be left doing it 6000 times.
The principle would also appy to fields but you would need to examine the arcpy methods, ListFeatureClasses, ListFields, AddField and arcpy.da cursors section of the help files in the arcpy section
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
Parser: Python
Expression=
!Facility_English!.split(":")[1]
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.
Best,
Majdoleen
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.
Hi Jayanta,
both have the same length= 50