[英]Splitting Large CSV file into multiple sheets in a single Excel using Python
I am using this piece of code for reading a csv(around 1 GB) using pandas and then writing into multiple excel sheets using chunksize.我正在使用这段代码使用 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()
This approach is taking a lot of time.Can anyone please suggest any approaches to reduce this time?这种方法需要很多时间。有人可以建议任何方法来减少这个时间吗?
Some days ago i have faced same problem so i tried with几天前我遇到了同样的问题,所以我尝试了
you can use library called as vaex [1]: https://vaex.readthedocs.io/en/latest/您可以使用名为 vaex [1] 的库: https://vaex.readthedocs.io/en/latest/
Or if you to to do itself with pandas try to use apache pyspark或者,如果您要自己使用 pandas 尝试使用 apache pyspark
Or use can use Google colud with 1200 credit或者使用可以使用 1200 credit 的 Google colud
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.