python - 通过并行处理将 xls 批量转换为 csv
问题描述
我定期将 30 gb xls 文件批量转换为 csv。为了减少时间我应该如何在 i5 windows pc 上使用并行处理。(它目前需要我 3 小时进行 30 GB 转换)。我是新手
import glob
import pandas as pd
excel_files = glob.glob(r'filepath\*.xls')
for excel in excel_files:
out = excel.split('.')[0] +'.csv'
df = pd.read_excel(excel) # if only the first sheet is needed.
df.to_csv(out)
具有多处理功能的代码现在可以工作,但比上面的代码花费更多时间(3 倍!)。阅读并发现可能是由于输入输出操作。我们可以加快速度吗?
import multiprocessing
import glob
import pandas as pd
excel_files = glob.glob(r'C:\Test\*.xls') # the path where your files are
counter= 0
def multi():
for excel in excel_files:
out = excel.split('.')[0] +'.csv'
df = pd.read_excel(excel) # if only the first sheet is needed.
df.to_csv(out)
return
if __name__ =='__main__':
#freeze_support()
queue = multiprocessing.Queue()
#num_cores=multiprocessing.cpu_count()
#print(num_cores)
pool = multiprocessing.Pool()
result= pool.map(multi,excel_files,8)
解决方案
推荐阅读
- asp.net - 每个下拉列表的单独 HTTP 请求或胖 FormViewModel 的单个请求?
- java - Selenium:如何在没有缓存的情况下启动 Web 浏览器
- ubuntu - xubuntu - 同时有多个活动窗口
- firebase - 有什么方法可以使用 Firestore 创建更新历史记录?
- python - sns.countplot,同一图中的多个 df 列
- pandas - 从分类变量创建新列
- android - 在我开始我的回收站视图之前,我如何让我的改造等到它完成
- c# - C# - 使用正则表达式验证电话号码
- wordpress - 如何转换 WordPress 标签每个单词的首字母大写
- wpf - 使用 XML 设置序列化实现消息抑制系统