我有多个巨大的数据框,我正尝试使用一个数据框的唯一标识符作为其他数据框的搜索基础进行映射。我想加快这个过程,因为整个过程需要6个小时以上才能完成。我当前正在做的是使用df[df['Column'] == 'Unique value']
方法在其他数据帧中搜索键,将匹配项串在一起并附加到新的数据帧中。此过程每个条目大约需要0.2秒,我觉得偏高了一点。我尝试使用apply.async()
作为并行化的一种方法,但是为每个唯一的密钥迭代创建的过程比在单个内核上运行它需要更多的时间。我可以采取哪些其他措施来加快速度?
我当前实施方式的相关摘要如下:
def indexer(df, index):
return df[df['Column'] == 'index']
def mapping:
with Pool(processes=3) as pool:
for i in df1.iloc[:,:]['Column'].unqiue():
p1 = pool.apply_async(indexer, (df1,index,))
p2 = pool.apply_async(indexer, (df2,index,))
p3 = pool.apply_async(indexer, (df3,index,))
df1 = p1.get()
df2 = p2.get()
df3 = p3.get()
谢谢您的建议!