我需要合并2个数据框:
Siren libelleVoieEtablissement
0 one
1 two
2 three
Siren denominationUniteLegale
0 A
1 B
3 D
4 E
我需要什么
Siren denominationUniteLegale libelleVoieEtablissement
0 A one
1 B two
2 NaN three
我得到的:
Siren denominationUniteLegale libelleVoieEtablissement
0 A one
1 B two
2 NaN three
3 D NaN
4 E NaN
我尝试过内部和外部,但是在这种情况下没有任何作用
df1 = pd.merge(df1, df2, on=['key'], how='left')
我不想要key = 3的行,怎么办?我将合并的“方式”更改为内部,外部和右侧,但是没有更好的方法了……
答案 0 :(得分:1)
我认为您正在寻找join()。
a = {'street':['one','two','three']}
b = {'name':['A','B','C','D']}
a = pd.DataFrame(a)
b = pd.DataFrame(b)
c = a.join(b)
c = c[['name','street']]
print(c)
输出:
name street
0 A one
1 B two
2 C three