【问题标题】:Memory error in python while running a csv of 300000 rows运行 300000 行的 csv 时 python 中的内存错误
【发布时间】:2019-06-05 17:17:50
【问题描述】:

当我尝试运行以下程序时出现上述错误。谁能解释一下什么是内存错误,以及如何解决这个问题?

这是在我尝试运行 csv 文件时。

如何解决这个问题?

tfidf = TfidfVectorizer(sublinear_tf=True, min_df=5, norm='l2', encoding='latin-1', ngram_range=(1, 2), stop_words='english')
features = tfidf.fit_transform(df.Consumer_complaint_narrative).toarray()
labels = df.category_id
features.shape
MemoryError                               Traceback (most recent call last)
<ipython-input-4-97e32167d120> in <module>
      1 from sklearn.feature_extraction.text import TfidfVectorizer
      2 tfidf = TfidfVectorizer(sublinear_tf=True, min_df=5, norm='l2', encoding='latin-1', ngram_range=(1, 2), stop_words='english')
----> 3 features = tfidf.fit_transform(df.Consumer_complaint_narrative).toarray()
      4 labels = df.category_id
      5 features.shape

F:\Anaconda3\lib\site-packages\scipy\sparse\compressed.py in toarray(self, order, out)
    960         if out is None and order is None:
    961             order = self._swap('cf')[0]
--> 962         out = self._process_toarray_args(order, out)
    963         if not (out.flags.c_contiguous or out.flags.f_contiguous):
    964             raise ValueError('Output array must be C or F contiguous')

F:\Anaconda3\lib\site-packages\scipy\sparse\base.py in _process_toarray_args(self, order, out)
   1185             return out
   1186         else:
-> 1187             return np.zeros(self.shape, dtype=self.dtype, order=order)
   1188 
   1189 

MemoryError: 

【问题讨论】:

    标签: python-3.x memory error-handling


    【解决方案1】:

    我通过更改 pycharm 中的 vmoption 修复了内存错误, 在 C:\Program Files\JetBrains\PyCharm 2018.1.4\bin\pycharm64.exe vmoption 文件中添加了 -Xmx5024m。这解决了我的记忆错误。我什至在 ssd 中使用了巨大的分页文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-24
      • 1970-01-01
      相关资源
      最近更新 更多