Код: Выделить всё
def CleanText(texto: str) -> str:
texto = texto.lower()
texto = ''.join((c for c in unicodedata.normalize('NFD', texto) if unicodedata.category(c) != 'Mn'))
texto = re.sub(r'[^a-z0-9 \n\.,]', '', texto)
texto = re.sub(r'([.,])(?![\s])', r'\1 ', texto)
texto = re.sub(r'\s+', ' ', texto).strip()
texto = texto.replace('.', '')
texto = texto.replace(',', '')
return texto
Код: Выделить всё
(
df
.with_columns(
pl.col("Comment").map_elements(CleanText,return_dtype=pl.String).alias("CleanedText")
)
)
Как я могу просто использовать полярное выражение, чтобы сделать то же самое?
Подробнее здесь: https://stackoverflow.com/questions/788 ... -on-polars