首页 > 解决方案 > 提高 jupyter notebook 中 python 代码的处理速度

问题描述

我有一个 Python 脚本,它处理 300 万行的数据集,CPU 使用率只有 25%,那么如何通过在 CPU 中使用多核或充分利用 CPU 来提高处理速度来提高处理速度呢?

多处理和进程池所需的输入。

标签: pythonpython-3.xjupyter-notebookanaconda

解决方案


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)

推荐阅读