I have a column of strings from which I wish to extract all consecutive uppercase words that appear in different cases. Here is an example of the type of strings I have:
data = pd.DataFrame({
'strings': ['ubicado en QUINTA CALLE, LADO NORTE detras',
'encuentra por AVENIDA NORTE, ARRIBA DE IGLESIA frente a',
'direccion en CENTRO COMERCIAL, SEGUNDO NIVEL junto a']
})
The lowercase words appear frequently enough to use them as regular expressions. Here is an example of what I have done so far:
df['extraction'] = df['strings'].str.extract('(?:(?<=ubicado en )|(?<=encuentra por )|(?<=direccion en ))(.*?)(?:(?=\s*detras)|(?=\s*frente\s*a)|(?=\s*junto\s*a))')
However, I would like to find a way to only use the first lowercase words and then apply a regex that would grab all the consecutive uppercase words.
Here is an example of what I am looking for:
df['extraction'] = df['strings'].str.extract('(ubicado\s*en\s*<REGEX>|encuentra\s*por\s*<REGEX>|direccion\s*en\s*<REGEX>)')
This should result in the following:
data = pd.DataFrame({
'extraction': ['QUINTA CALLE, LADO NORTE',
'AVENIDA NORTE, ARRIBA DE IGLESIA',
'CENTRO COMERCIAL, SEGUNDO NIVEL']
})
The strings are actually much longer and complex texts, so I cannot simply remove all lowercase letters in the column.