简体   繁体   English

如何在不占用大量内存的情况下读取泡菜文件

[英]How to read pickle files without taking up a lot of memory

Currently I have a loop that contains: 目前,我有一个循环,其中包含:

df = pandas.read_pickle(filepath)

the files are ~ 100 mb. 文件约为100 mb。 However since it is looping through these many times, it is taking up a lot of memory and then eventually I get a memory error. 但是,由于它遍历了很多次,因此占用了大量内存,然后最终出现内存错误。 Is there a way to do this where I can close the file once I get the dataframe? 有没有一种方法可以在我得到数据框后关闭文件?

My code is correct because I've tested it with less files. 我的代码是正确的,因为我用更少的文件进行了测试。 I just want an alternative to reading large pickle files without taking up too much memory after I read it. 我只希望在读取大型泡菜文件后不占用太多内存的情况下找到另一种选择。

del df
gc.collect()

Erase reference, and garbage colector. 擦除参考和垃圾收集器。

Edit, this erase your dataframe from memory, you can not close the file, take the info and dont use ram. 编辑,这会从内存中删除数据框,您无法关闭文件,获取信息并且不要使用ram。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM