Я пытаюсь бросить регулярное выражение в текстовом файле 500 МБ:
with open(f'{trn_path}text.00') as file:
df_trn = file.readlines()
re1 = re.compile(r' +')
def fixup(x):
x.replace('>', '').replace('<', '').replace('doc', '').replace(':',
'').replace('t_up', '').replace(
'fi.wikipedia.org', '').replace('url="https', '').replace('\xa0','')
return re1.sub(' ', html.unescape(x))
df_trn = pd.Series(df_trn)
df_trn = df_trn.apply(fixup).values.astype(str)
Дает мне
MemoryError:
Если я читаю файл chunksize
df_trn.to_csv(f'{trn_path}train.csv', header=False, index=False)
df_trn = pd.read_csv(f'{trn_path}train.csv', header=None, chunksize=chunksize)
Я получаю
AttributeError: 'TextFileReader' object has no attribute 'apply'
Есть идеи?Спасибо!