Pandas具有出色的.read_table()
功能,但是巨大的文件会导致内存错误。
因为我只需要加载满足特定条件的行,所以我正在寻找一种只加载这些行的方法。在
这可以使用临时文件来完成:
with open(hugeTdaFile) as huge:
with open(hugeTdaFile + ".partial.tmp", "w") as tmp:
tmp.write(huge.readline()) # the header line
for line in huge:
if SomeCondition(line):
tmp.write(line)
t = pandas.read_table(tmp.name)
有没有办法避免这种临时文件的使用?在
可以使用chunksize参数返回迭代器
看这个:http://pandas.pydata.org/pandas-docs/stable/io.html#iterating-through-files-chunk-by-chunk
(或者,您可以将它们写到新的CSV或HDF存储库或其他地方)
相关问题 更多 >
编程相关推荐