我有以下两个数据帧:
DF1:
Id | field_A | field_B | field_C | field_D
1 | cat | 12 | black | 11
2 | dog | 128 | white | 19
3 | dog | 35 | yellow | 20
4 | dog | 21 | brown | 4
5 | bird | 10 | blue | 7
6 | cow | 99 | brown | 34
和
DF2:
Id | field_B | field_C | field_D | field_E
3 | 35 | yellow | 20 | 123
5 | 10 | blue | 7 | 454
6 | 99 | brown | 34 | 398
我希望得到new_DF作为
Id | field_A | field_B | field_C | field_D | field_E
1 | cat | 12 | black | 11 |
2 | dog | 128 | white | 19 |
3 | dog | 35 | yellow | 20 | 123
4 | dog | 21 | brown | 4 |
5 | bird | 10 | blue | 7 | 454
6 | cow | 99 | brown | 34 | 398
可以通过数据帧操作实现吗?谢谢!
try this:
new_df = df1.join(df2, on=['field_B', 'field_C', 'field_D'], how='left_outer')