Я пытаюсь обработать большое количество текстов размером почти 2 ГБ в Windows 64-битном режиме. Однако, когда я запускаю коды для понижения, токенизации и удаления стоп-слов, я получаю MemoryError
. Вот код, который я использую, и сообщение об ошибке, которое я получаю взамен.
import nltk
from nltk.corpus import stopwords
import string
stop = stopwords.words('english') + list(string.punctuation)
df3['p_text'] = df3.text_x.str.replace("[^\w\s]", "").str.lower()
df3['p_text'] = df3['text_x'].apply(lambda x: [item for item in x.split() if item not in stop])
---------------------------------------------------------------------------
MemoryError Traceback (most recent call last)
<ipython-input-184-c2604aadd142> in <module>
----> 1 df3['p_text'] = df3.text_x.str.replace("[^\w\s]", "").str.lower()
2 df3['p_text'] = df3['text_x'].apply(lambda x: [item for item in x.split() if item not in stop])
~\Anaconda3\lib\site-packages\pandas\core\strings.py in wrapper(self, *args, **kwargs)
1952 )
1953 raise TypeError(msg)
-> 1954 return func(self, *args, **kwargs)
1955
1956 wrapper.__name__ = func_name
~\Anaconda3\lib\site-packages\pandas\core\strings.py in replace(self, pat, repl, n, case, flags, regex)
2775 def replace(self, pat, repl, n=-1, case=None, flags=0, regex=True):
2776 result = str_replace(
-> 2777 self._parent, pat, repl, n=n, case=case, flags=flags, regex=regex
2778 )
2779 return self._wrap_result(result)
~\Anaconda3\lib\site-packages\pandas\core\strings.py in str_replace(arr, pat, repl, n, case, flags, regex)
724 f = lambda x: x.replace(pat, repl, n)
725
--> 726 return _na_map(f, arr, dtype=str)
727
728
~\Anaconda3\lib\site-packages\pandas\core\strings.py in _na_map(f, arr, na_result, dtype)
129 if na_result is None:
130 na_result = np.nan
--> 131 return _map_object(f, arr, na_mask=True, na_value=na_result, dtype=dtype)
132
133
~\Anaconda3\lib\site-packages\pandas\core\strings.py in _map_object(f, arr, na_mask, na_value, dtype)
214 convert = not np.all(mask)
215 try:
--> 216 result = lib.map_infer_mask(arr, f, mask.view(np.uint8), convert)
217 except (TypeError, AttributeError) as e:
218 # Reraise the exception if callable `f` got wrong number of args.
pandas\_libs\lib.pyx in pandas._libs.lib.map_infer_mask()
~\Anaconda3\lib\site-packages\pandas\core\strings.py in <lambda>(x)
712 n = n if n >= 0 else 0
713 compiled = re.compile(pat, flags=flags)
--> 714 f = lambda x: compiled.sub(repl=repl, string=x, count=n)
715 else:
716 f = lambda x: x.replace(pat, repl, n)
MemoryError: