我有一个包含约 50,000 行和 300 列的 csv 文件。执行以下操作会导致 Pandas (python) 中出现内存错误:
merged_df.stack(0).reset_index(1)
数据框看起来像:
GRID_WISE_MW1 Col0 Col1 Col2 .... Col300
7228260 1444 1819 2042
7228261 1444 1819 2042
我使用的是最新的 pandas (0.13.1),该错误不会出现在行数较少的数据帧 (~2,000)
谢谢!
最佳答案
所以它占用了我的 64 位 Linux (32GB) 内存,略小于 2GB。
In [5]: def f():
df = DataFrame(np.random.randn(50000,300))
df.stack().reset_index(1)
In [6]: %memit f()
maximum of 1: 1791.054688 MB per loop
因为你没有指定。这在 32 位上根本不起作用(因为您通常不能分配 2GB 的连续 block ),但如果您有合理的交换/内存,应该可以工作。
关于python - Pandas 内存错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23205005/