pandas get_group内存错误

时间:2015-11-06 23:41:18

标签: python-2.7 pandas

我正在使用pandas v0.14.1和python 2.7

我有一个groupby对象,我正在尝试提取一个由特定密钥标识的组。事实上关键在于小组:

>>> key in key_groups.groups.keys()
True

但是当我尝试进行get_group调用时,它会因内存错误而失败:

>>>> key_groups.get_group(key)
*** MemoryError:

完整的堆栈跟踪是:

Traceback (most recent call last):
  File "main.py", line 141, in <module>
    main(num_days=arguments.days, num_variants=arguments.variants)
  File "main.py", line 76, in main
    problem, solution = Solver.Solve(request, num_variants)
  File "/srv/compunctuator/src/Solver.py", line 49, in Solve
    solution = attempt_minimization(t)
  File "/srv/compunctuator/src/Solver.py", line 41, in attempt_minimization
    t.scruple()
  File "/srv/compunctuator/src/Compunctuator.py", line 136, in scruple
    self.__iterate__()
  File "/srv/compunctuator/src/Compunctuator.py", line 95, in __iterate__
    self.__maximize_impressions__()
  File "/srv/compunctuator/src/Compunctuator.py", line 583, in __maximize_impressions__
    df = key_groups.get_group(key)
  File "/srv/compunctuator/.virtualenvs/compunctuator/local/lib/python2.7/site-packages/pandas/core/groupby.py", line 573, in get_group
    inds = self._get_index(name)
  File "/srv/compunctuator/.virtualenvs/compunctuator/local/lib/python2.7/site-packages/pandas/core/groupby.py", line 429, in _get_index
    sample = next(iter(self.indices))
  File "/srv/compunctuator/.virtualenvs/compunctuator/local/lib/python2.7/site-packages/pandas/core/groupby.py", line 414, in indices
    return self.grouper.indices
  File "properties.pyx", line 34, in pandas.lib.cache_readonly.__get__ (pandas/lib.c:36380)
  File "/srv/compunctuator/.virtualenvs/compunctuator/local/lib/python2.7/site-packages/pandas/core/groupby.py", line 1253, in indices
    return _get_indices_dict(label_list, keys)
  File "/srv/compunctuator/.virtualenvs/compunctuator/local/lib/python2.7/site-packages/pandas/core/groupby.py", line 3474, in _get_indices_dict
    np.prod(shape))
  File "algos.pyx", line 1997, in pandas.algos.groupsort_indexer (pandas/algos.c:37521) MemoryError

如果我实际使用字典查找,我可以得到索引:

>>>> key_groups.groups[key]
[0, 2]

似乎一切都应该在这里工作。

我意识到这里有一个类似的问题pandas get_group causes memory error 但它从未得到解决,我想如果有必要我可以提供更多细节。

0 个答案:

没有答案