Introducción a la manipulación de strings

Expresiones regulares en Python

Maria Eugenia Inzaugarat

Data Scientist

Aprenderás

  • Manipulación de strings

    • p. ej., reemplazar y buscar subcadenas
  • Formateo de strings

    • p. ej., interpolar un string en una plantilla
  • Expresiones regulares básicas y avanzadas

    • p. ej., buscar patrones complejos en un string
Expresiones regulares en Python

Por qué es importante

  • Limpiar datos para preparar minería de texto o análisis de sentimiento

  • Procesar correos para un algoritmo que decide si es spam

  • Parsear y extraer datos de una web para crear una base de datos

Expresiones regulares en Python

Strings

  • Secuencia de caracteres

  • Comillas

my_string = "This is a string"
my_string2 = 'This is also a string'
my_string = 'And this? It's the wrong string'
my_string = "And this? It's the correct string"
Expresiones regulares en Python

Más sobre strings

  • Longitud
my_string = "Awesome day"

len(my_string)
11
  • Convertir a string
str(123)
'123'
Expresiones regulares en Python

Concatenación

  • Concatenar: operador +
my_string1 = "Awesome day"
my_string2 = "for biking"
print(my_string1+" "+my_string2)
Awesome day for biking
Expresiones regulares en Python

Indexación

  • Notación de corchetes

my_string = "Awesome day"
print(my_string[3])
s

 

print(my_string[-1])
y
Expresiones regulares en Python

Slicing

  • Notación de corchetes

my_string = "Awesome day"
print(my_string[0:3])
Awe

 

print(my_string[:5])
print(my_string[5:])
Aweso
me day
Expresiones regulares en Python

Paso (stride)

  • Especificar el paso

my_string = "Awesome day"
print(my_string[0:6:2])
Aeo

 

print(my_string[::-1])
yad emosewA
Expresiones regulares en Python

¡Vamos a practicar!

Expresiones regulares en Python

Preparing Video For Download...