【问题标题】:Splitting Large CSV file into multiple sheets in a single Excel using Python使用 Python 在单个 Excel 中将大型 CSV 文件拆分为多个工作表
【发布时间】:2020-08-12 06:30:17
【问题描述】:

我正在使用这段代码使用 pandas 读取 csv(大约 1 GB),然后使用 chunksize 写入多个 excel 表。

with pd.ExcelWriter('/tmp/output.xlsx',engine='xlsxwriter') as writer:
        reader = pd.read_csv(f'/tmp/{file_name}', sep=',', chunksize=1000000)
        for idx, chunk in enumerate(reader):
            chunk.to_excel(writer, sheet_name=f"Report (P_{idx + 1})", index=False)
        writer.save()

这种方法需要很多时间。有人可以建议任何方法来减少这个时间吗?

【问题讨论】:

  • 你只想使用 Pandas 库吗?还有其他库可以更好地实现此目的。
  • 我可以使用其他 Python 包,只要它们是开源的并且没有任何许可问题。
  • 这能回答你的问题吗? Pandas - split large excel file
  • 你可以使用 python 的 csv 模块和 openpyxl 来做到这一点。这里不需要 Pandas,因为不涉及数据操作。看看我的answer 看看它是否相关。另外,您目前的流程需要多长时间?
  • 我终于在我的用例中使用了PyExcelerate

标签: python python-3.x pandas pandas.excelwriter


【解决方案1】:

几天前我遇到了同样的问题,所以我尝试了

您可以使用名为 vaex 的库 [1]:https://vaex.readthedocs.io/en/latest/

或者如果你想用 pandas 自己做尝试使用 apache pyspark

或者可以使用 Google colud 1200 credit

【讨论】:

  • 我想将大型 csv 写入包含多张工作表的 excel。我无法在此包中找到任何与 excel 相关的实用程序。可视化不是我的要求。
  • 然后在没有选项的情况下使用 google colab 或 google clod 免费 esle
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-19
  • 1970-01-01
  • 2014-12-20
  • 1970-01-01
  • 1970-01-01
  • 2017-01-27
相关资源
最近更新 更多