内关联
import pandas as pd
df1 = pd.read_csv(r'score_20200625.csv', encoding='utf_8', low_memory=False)
df2 = pd.read_csv(r'score_20200727.csv', encoding='utf_8', low_memory=False)
# 内关联
df3 = pd.merge(left=df2, right=df1, how='inner',
left_on='bd_code', right_on='bd_code')
# 保存内关联的结果
df3.to_csv('inner_join.csv', header=True, index=True)
左关联
import pandas as pd
df1 = pd.read_csv(r'score_20200625.csv', encoding='utf_8', low_memory=False)
df2 = pd.read_csv(r'score_20200727.csv', encoding='utf_8', low_memory=False)
# 左关联
df3 = pd.merge(left=df2, right=df1, how='left',
left_on='bd_code', right_on='bd_code')
# 取没有关联上的部分
df3 = df3[df3.isnull().T.any()]
# 保存左关联的结果
df3.to_csv('left_join.csv', header=True, index=True)