小编W O*_*rio的帖子

多个 pandas 数据帧作为多处理的参数

我对 Python 有点陌生,所以如果这是一个愚蠢的问题,我想道歉。

我目前正在开发一项执行多项数据检查的开发。

简而言之,我有一个主数据框,需要根据其他数据框的数据进行验证。

我所做的代码在单核上正常工作,但由于体积的原因,我需要实现多核处理。问题是我找不到如何将多个 pandas 数据帧作为参数传递给函数模块。

请注意,主数据集purchase_orders已经在进程之间进行了分割,因此每个进程将收到1/4的数据。其他数据帧应该更小并且完全相同,因此如果有一种方法可以使生成的进程访问在主进程上创建的数据帧也很好,因为我只会从中读取数据。

数据帧change_log和参数将在apply方法中使用。

代码如下:

# this is the code I would like to call for multi processing
def apply_scores_test(purchase_orders, change_log, parameters):
    print('Running multicore')
    size = 1
    g_first = 'X'
    g_results = 'START'
    g_temp_lifnr = 'X'
    purchase_orders = purchase_orders.apply(calculate_scores, axis=1)
    return purchase_orders

# Starting the multi-core processing (locked to 4 process to make it easier to test)
p = multiprocessing.Pool(4) 
args = [(g_purchase_orders_1, change_log, parameters), (g_purchase_orders_2, change_log, parameters), (g_purchase_orders_3, change_log, parameters),(g_purchase_orders_4, change_log, parameters),]
res …
Run Code Online (Sandbox Code Playgroud)

multiprocessing dataframe pandas

6
推荐指数
1
解决办法
2078
查看次数

标签 统计

dataframe ×1

multiprocessing ×1

pandas ×1