使用pandas加载经过筛选的.tda文件的最简单方法是什么?

2024-09-29 23:23:00 发布

您现在位置:Python中文网/ 问答频道 /正文

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)

有没有办法避免这种临时文件的使用?在


Tags: 文件内存功能pandasreadas错误with

热门问题