微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

熊猫 DataFrame 的 Modin 与线程

如何解决熊猫 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 举报,一经查实,本站将立刻删除。