Python,制作数据框时出现内存错误 [英] Python, Memory Error in making dataframe

查看:59
本文介绍了Python,制作数据框时出现内存错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用pandas DataFrame时,发生内存错误.

When I use pandas DataFrame, occuring the Memory Error.

数据的行是200000,列是30.(类型:列表) fieldnames1具有列名.(类型:列表)

data's row is 200000 and column is 30.(type: list) fieldnames1 has columns name.(type:list)

错误发生在:

df = pd.DataFrame(data,columns=[fieldnames1])

我该怎么办? (python版本2.7 32位)

what should I do? (python version 2.7 32bit)

推荐答案

正如克劳斯(Klaus)所指出的,您的内存不足.当您尝试一次将整个文本拉到内存中时,就会出现问题.

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.

Wes McKinney在 中指出,解决方案是读取较小的文件(使用iterator=True, chunksize=1000),然后连接,然后使用pd.concat".

As pointed out in this post by Wes McKinney, "a solution is to read the file in smaller pieces (use iterator=True, chunksize=1000) then concatenate then with pd.concat".

这篇关于Python,制作数据框时出现内存错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆