【问题标题】:Reading huge csv files efficiently?有效地读取巨大的 csv 文件?
【发布时间】:2015-11-13 09:24:03
【问题描述】:

我知道如何使用 pandas 读取具有 CSV 扩展名的文件。读取大文件时出现内存不足错误。该文件是 380 万行和 640 万列的文件。大种群文件中主要有基因组数据。

我该如何克服这个问题,什么是标准做法以及如何为此选择合适的工具。我可以用 pandas 处理这么大的文件吗?还是有其他工具?

【问题讨论】:

  • 您需要阅读整个文件吗?您可以将chunksize 参数传递给read_csv 并处理块
  • 也许可以帮助this question

标签: csv pandas bigdata


【解决方案1】:

您可以使用 Apache Spark 分发 csv 文件 https://github.com/databricks/spark-csv 的内存处理。看看ADAM's 分布式基因组数据处理的方法。

【讨论】:

    【解决方案2】:

    可以使用pythoncsv模块

    with open(filename, "r") as csvfile:
        datareader = csv.reader(csvfile)
        for i in datareader:
            #process each line
            #You now only hold one row in memory, instead of your thousands of lines
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-29
      • 2020-08-05
      • 1970-01-01
      • 2015-06-02
      • 2012-08-30
      相关资源
      最近更新 更多