Python多处理和熊猫-共享内存

时间:2018-10-16 01:35:48

标签: python pandas multiprocessing shared-memory

我有15个大数据帧(每个26000x2500)。我目前将它们作为数据帧的字典,但是可以根据需要进行更改。

我需要在每列上执行操作(大约2500个),并且它们是完全独立的,因此我认为这是并行处理的理想选择。目前,我的代码可以在几个小时内运行,但是我想使其更快。

这是我的代码结构:

Main.py

import Processor

# Build dataframes from CSV files
dataframes = ...
p = Processor(dataframes)
p.run()

Processor.py

import multiprocessing as mp

class Processor():
    def __init__(self, dataframes):
        self._dataframes = dataframes

    def run():
        # Loop at each column
            # Launch new process and perform operations on column
            # Receive results back and store them

我有2个问题:

  1. 实现并行处理(进程或池)的最佳方法是什么?
  2. 如何共享内存中的数据帧,这样就不必将它们复制到每个线程/进程中?

0 个答案:

没有答案
相关问题