POST
|
I recently place a question on how to change the placement of a combination of digits, letter or digits and letters in the rows of a single field in a dBase file so that it follow a particular output format. I got many helpful responses and am now trying to take this to the next level. The digits and letters in each row are different lengths and do not follow any standard pattern. Here are three examples for hypothetical values: 12NESW3SESE NWNW 1. The first contains a combination of digits and letters, the second, letters only, and the third a single digit The desired modification follows a rule where starting at the left of the string, the first consecutive digits, if any, are to be placed after the first consecutive letters, if any, separated by a semicolon, and the next consecutive digits, if any, are to be place after the next consecutive letters, if any, separated by and semicolon. A comma is placed between any modified set of combo sets of letters;digits. This patter continues regardless of the number of sets of digits or letters. So, the three rows above are changed to NESW;12,SESE;3 NWNW ;1. I used a script provided by Darren Wiens in his response to my original post. His script works perfect. However, it uses a single quoted value for variable aa. I attempted to modify the script as posted below, so that it would change the values per arcpy.da.UpdateCursor and changing variable aa = row[0]. I have a couple of failures. First, the final list does not include the characters from list_2. Second, I receive a a runtime error "NameError: name 'cursor' is not defined". I am attaching a small sample dbf table with the original values in the field "aliquot_pa" and the desired modifications shown in the field "format". I am wanting to update "aliquot_pa" to match "format". Thanks all of you that responded before and any help with this is very much appreciated. Bob Schoolar featureClass = "E:\\GLO_Conversion\\test.dbf" fields = ('aliquot_pa') with arcpy.da.UpdateCursor(featureClass,fields) as cursor: for row in cursor: aa = row[0] prev_type = aa[0].isdigit() list_1 = [] cur_word = '' for char in aa: if char.isdigit() == prev_type: cur_word += char else: list_1.append(cur_word) cur_word = char prev_type = char.isdigit() list_1.append(cur_word) print list_1 list_2 = [] for i in range(0,len(list_1),14): list_2.append(list_1[i+1] + ';' + list_1) print list_2 final_list = ','.join(list_2) print final_list cursor.updateRow(row) del cursor del row
... View more
08-31-2016
04:13 PM
|
0
|
3
|
864
|
POST
|
Dan, Thanks for the script and taking time to explain verbosely. I am making progress for sure with all this great help. I've got 370 thousand records to process on the first set and 13 sets to process. Such powerful coding. Bob
... View more
08-10-2016
08:46 PM
|
0
|
1
|
212
|
POST
|
Thanks Darren, Looks very much like the code I might need. However, as I am still in a steep learning curve, I will have to digest and understand along with other comments to put this to work land records. Bob
... View more
08-10-2016
02:58 PM
|
0
|
0
|
649
|
POST
|
Thanks Rebecca, This is very helpful. Unfortunately, it is not a fixed format. The second record might be something like SW6SWNENENE or even records with no capital letter such as 1. The target format for these two examples would be SW,SWNENENE;6 and simply ;1 , Bob
... View more
08-10-2016
02:47 PM
|
0
|
0
|
649
|
POST
|
I am new at Python. I have a dbf table with a text field. Some of the records contain one or two digit numbers at the beginning followed by a string various capital letters which may then be followed by one or two digit numbers and another string of capital letters. Example: 12NESW3SESE. This is just one example of many combinations of numbers and letters. I need to change the order of the records so that the initial one or two digit number follows, rather than precedes, the letters until it gets to the second instance of a one or two digit number. Likewise, the second instance of one or two digit numbers needs to be moved to the end of the second sequence of capital letters. Also, in all cases a semicolon needs to precede the one or two digit number and a comma after the first set of one or two digit numbers and before the second set of capital letters. Hence, the example should be revised to NESW;12,SESE;3
... View more
08-10-2016
01:29 PM
|
0
|
12
|
1967
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|