Python 如何高效地合并两列上的两个dataframe

Python 如何高效地合并两列上的两个dataframe,python,pandas,Python,Pandas,我有两个相当大的数据帧(大约200万行) 它们都有两个共同的列('CD'和'BA'),我想在这两个列上加入我的数据帧 我有很多解决方案,但目前它们都需要很长的时间(超过7秒) 你知道如何加快速度吗 对于200万行数据来说,7秒和7秒也不错。@coldspeed-它是左连接,所以concat不可能使用-它只用于内部和外部连接。@jezrael哦,对了,谢谢 affect = df1.merge(df2, on=['BA', 'CD'], how='left') affect = df1.set_

我有两个相当大的数据帧(大约200万行)

它们都有两个共同的列('CD'和'BA'),我想在这两个列上加入我的数据帧

我有很多解决方案,但目前它们都需要很长的时间(超过7秒)


你知道如何加快速度吗

对于200万行数据来说,7秒和7秒也不错。@coldspeed-它是左连接,所以
concat
不可能使用-它只用于内部和外部连接。@jezrael哦,对了,谢谢
affect = df1.merge(df2, on=['BA', 'CD'], how='left')

affect = df1.set_index(['BA', 'CD']).join(df2.set_index(['BA', 'CD']), how='left')

df1.set_index(['BA', 'CD'], inplace=True)
df2.set_index(['BA', 'CD'], inplace=True)
affect = df1.join(df2, how='left')