我有两个数据框:
df1:
time | fruit | seller | supermarket | price |
1 | apple | ted | tesco | 1.3 |
2 | banana | bob | sains | 0.7 |
3 | pear | bob | sains | 0.7 |
4 | apple | bob | mands | 1.3 |
5 | orange | jen | mands | 0.5 |
df2:
time | fruit | supermarket | price |
1 | apple | tesco | 1.3 |
3 | pear | sains | 0.7 |
5 | orange | mands | 0.5 |
我想根据df1和df2中[时间,水果,超市,价格]列下的变量是否直接匹配来在df1中创建新列:
df1_updated:
time | fruit | seller | supermarket | price | in_df2 |
1 | apple | ted | tesco | 1.3 | True |
2 | banana | bob | sains | 0.7 | False |
3 | pear | bob | sains | 0.7 | True |
4 | apple | bob | tesco | 1.3 | False |
5 | orange | jen | mands | 0.5 | True |
即。必须与[时间,水果,超市,价格]中的所有列都匹配
我知道如何使用df1中的行进行for循环,并对照df2中的行进行检查,但是我可以通过合并或联接来做到这一点吗?