I wrote a function that cleans the text of a given string. And I apply this function to a column in a dataframe(~ 1 million records).
from cleanco import cleanco
import re
import pandas as pd
import unidecode
def clean_name(text):
#convert plain text to utf-8
text = unidecode.unidecode(text)
text = text.upper()
text = re.sub('[()]', '', text)
text = text.replace(',' , '')
text = text.replace(' - ', ' ')
text = text.replace(r"\(.*\)","")
text = text.replace(' AND ', ' & ')
text = text.strip()
x = cleanco(text)
text = x.clean_name()
text = text.replace('.', '')
text = text.title()
return text
df['name_clean'] = customer_info_df['name'].apply(utils.clean_name)
While the function gets the job done, the performance speed seems to be a bit long (~13-15mins) to finish a dataframe of over 1 million rows. Are there any alternatives to increase the speed and effeciency?