ausiddiqui/maya

merge the data processing python files

ausiddiqui opened this issue · 0 comments

Merge the two files data_cleaning.py and preprocessor.py.

Consolidate the changes. Also if using substitution / regular expressions using DataFrames consider using lambda functions as it is considerably faster, especially for string functions / regex. See:

# Strip whitespace
import re
import pandas as pd

body = ["document1       file1", "document2  example222", "document3"]
df_body = pd.DataFrame(body, columns=['body_text'])

# substitute RE_WHITESPACE with any regular expression, where is of the format re.sub(**regular expression**, **substitute character**, **input string**)
RE_WHITESPACE = re.compile(r'[\s]{2,}')
df_body['body_text'] = df_body['body_text'].apply(lambda x: re.sub(RE_WHITESPACE, '', x))