熊猫 DataFrame 的 Modin 与线程

问题描述

我有一个包含 343,500 条记录的 DataFrame 和一个预定义的 get_zipcode 函数

为了加速 apply,我将数据分成四份,并使用 threading 模块创建了以下线程化进程:

df['subsections'] = np.resize([1,2,3,4],len(df))

if __name__ == '__main__':
    t1 = threading.Thread(target=df.loc[(df['EMPTY'] == True) & (df['subsections'] == 1)].apply(lambda x: get_zipcode(lat=x['LATITUDE'],lon=x['LONGITUDE']),axis=1))
    t2 = threading.Thread(target=df.loc[(df['EMPTY'] == True) & (df['subsections'] == 2)].apply(lambda x: get_zipcode(lat=x['LATITUDE'],axis=1))
    t3 = threading.Thread(target=df.loc[(df['EMPTY'] == True) & (df['subsections'] == 3)].apply(lambda x: get_zipcode(lat=x['LATITUDE'],axis=1))
    t4 = threading.Thread(target=df.loc[(df['EMPTY'] == True) & (df['subsections'] == 4)].apply(lambda x: get_zipcode(lat=x['LATITUDE'],axis=1))

    t1.start()
    t2.start()
    t3.start()
    t4.start()
    
    t1.join()
    t2.join()
    t3.join()
    t4.join()

这似乎工作得相当好。但后来我发现了 modin module,它(根据我对文档的理解)也使用了多线程。

在这种情况下,我实质上是在整个数据帧中apply调用一个函数,使用 threadingmodin 相比是否有优势?

从更广泛的意义上讲,根据文档,使用 modin 是否有优势?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)