I have a table with multiple rows, row a and row b. Row a has several species names separated by an enter key and a capital letter. I want to separate each species into its own row, and replicate row b. Here is the code I'm using, but I'm not sure how to make it upper case.
import arcpy
import os
import sys
from arcpy import env
from arcpy.sa import Con
from arcpy.sa import *
SC_table = r'D:\Data\Biological\SC\SC 2022\SC_2022.gdb\SC_table_2023'
new_sc_table = r'D:\Analysis\Biological_Update\Occurrences_Updates\December_2022_Updates\OUTPUT\Species_TablesbyState_2022.gdb\SC_table_Schema_2023'
searchC = arcpy.da.SearchCursor(SC_table, ("spp_list", "HUC12")) # plus other attribute if you need
insertC = arcpy.da.InsertCursor(new_sc_table, ("spp_list", "HUC12"))
for row in searchC:
print(row[0])
A = [x.split(" ") for x in row[0]
for i in range(min(len(A[0]), len(A[1]))):
newRow = [A[0][i], A[1][i]]
insertC.insertRow(newRow)
del insertC
in python ... yourstring.upper()
ps you are missing a closing ] on line 17
[x.split(" ") for x in row[0]] # -- added ]
Thank you! Sorry, how can that be integrated into the script above?
perhaps showing a typical input and desired output would help, but as a guess for now
r = ["row0 value here"]
[(x.upper()).split(" ") for x in r]
# -- yields
[['ROW0', 'VALUE', 'HERE']]
@KathleenHoenke Would this code snip help you? It finds words in a string that start with capital leters.
import re
text = "HelloWorldHowAreYou"
# Regular expression pattern to split the string using capital letters
pattern = r"[A-Z][a-z]*"
result = re.findall(pattern, text)
print(result) #['Hello', 'World', 'How', 'Are', 'You']