简体   繁体   English

使用 Python 将大型 CSV 文件拆分为单个 Excel 中的多个工作表

[英]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.

相关问题 通过更改标题将.csv文件中的单个列拆分为多个列,并使用Python 2将其保存到新的.csv文件中 - Splitting a single column in a .csv file into multiple columns with changes in headings and saving it in a new .csv file using Python 2 使用 Python 3 将大型 CSV 文件转换为 Excel - Convert large CSV file to excel using Python 3 使用 Python 将 CSV 文件中的单行文本拆分为同一列的多行 - Splitting text of a single row into multiple rows of the same column in a CSV file using Python 根据行限制参数将CSV文件拆分为Excel文件中的多个工作表 - Splitting CSV file into multiple sheets in an Excel file based on row limit argument Python-将单个csv单元拆分为多个单元 - Python - Splitting a single csv cell into multiple cells 使用Python 3将多个Excel工作簿和工作表导入到单个数据框中 - Using Python 3 to import multiple excel workbooks and sheets into single data frame 使用python将csv文件拆分为具有重叠行的多个文件 - Splitting a csv files into multiple file with overlapping rows using python 使用 Pandas 拆分大型 excel 文件 - splitting a large excel file using pandas 如何将多个excel表转换为csv python - How to convert multiple excel sheets to csv python 拆分单个大型 csv 文件以按两列重新采样 - Splitting a single large csv file to resample by two columns
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM