[英]What is the easiest way to load a filtered .tda file using pandas?
熊猫具有出色的.read_table()
函数,但大文件会导致MemoryError。
由于只需要加载满足特定条件的线,因此我正在寻找一种仅加载那些条件的线。
这可以使用一个临时文件来完成:
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
(或者,您可以将它们写到新的csvs或HDFStores或其他内容中)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.