pandas Python,制作数据帧时出现内存错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31241449/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python, Memory Error in making dataframe
提问by ???
When I use pandas DataFrame, occuring the Memory Error.
当我使用 pandas DataFrame 时,发生Memory Error。
data's row is 200000 and column is 30.(type: list) fieldnames1 has columns name.(type:list)
数据的行是 200000,列是 30。(类型:列表) fieldnames1 有列名称。(类型:列表)
Error occured in:
错误发生在:
df = pd.DataFrame(data,columns=[fieldnames1])
what should I do? (python version 2.7 32bit)
我该怎么办?(python 版本 2.7 32 位)
回答by Julien Marrec
As indicated by Klaus, you're running out of memory. The problem occurs when you try to pull the entire text to memory in one go.
正如 Klaus 所指出的,您的内存不足。当您尝试一次性将整个文本拉入内存时,就会出现问题。
As pointed out in this postby Wes McKinney, "a solution is to read the file in smaller pieces (use iterator=True, chunksize=1000) then concatenate then with pd.concat".
正如Wes McKinney在这篇文章中指出的那样,“一个解决方案是读取更小的文件(使用iterator=True, chunksize=1000),然后与 pd.concat 连接”。
回答by Javeria
You can try this line of code:
你可以试试这行代码:
data=pd.DataFrame.from_csv("train.csv")
This is an alternate of read.csv but it returns Data frame object without giving any memory error P.S the size of the training data is around 73 mb
这是 read.csv 的替代方案,但它返回数据框对象而不会给出任何内存错误 PS 训练数据的大小约为 73 mb

