python - 提高 jupyter notebook 中 python 代码的处理速度
问题描述
我有一个 Python 脚本,它处理 300 万行的数据集,CPU 使用率只有 25%,那么如何通过在 CPU 中使用多核或充分利用 CPU 来提高处理速度来提高处理速度呢?
多处理和进程池所需的输入。
解决方案
import multiprocessing
pool = multiprocessing.Pool(multiprocessing.cpu_count())
def some_function_you_want_executed_in_parallel(args):
pass # logic goes here
arg_list = [] # put input arguments here
results = pool.map(some_function_you_want_executed_in_parallel, arg_list)
推荐阅读
- python - 占位符和仅查看 Django 模型表单中的值
- symfony - API 平台 - 如何创建自定义收集操作 (GET)?
- uwp - 在 Windows 应用程序中拖放项目并获取项目的 StandardDataFormats
- python - Django 3图像和文件上传不通过表单保存
- jmeter - 有没有办法在 Jmeter 变量中使用 Loopnum 而不是 threadNum
- spring-boot - Jedis java.net.socketException: Broken pipe (Write failed)
- sql - 窗函数滚动和
- android - 使用 kotlin 通过 webview 启用下载
- gitlab-ci - 当 testcontainer 无法启动时,集成测试管道不会失败
- shell - 如何有效地将多个文件加载到hadoop的同一路径中?