我想将CustomerMail上的DF1
与DF2
合并,这在两者中都很常见,但具有重复值。
DF1
customer_Email Fraud
name_0 False
name_1 True
name_2 True
name_3 True
name_4 False
name_1 False
DF2
customer_Email ID
name_0 0
name_1 1
name_2 2
name_3 3
name_4 4
name_1 5
请注意,DF1和DF2仅用于示例目的
customerEmail
在两个数据帧中都不是唯一的
因此,当我使用pd.merge(DF1, DF2, on='customerEmail', how=left)
连接这两个表时,当相同的customerEmail
重复时,它会用上面行中的随机值填充目标列Fraud
当customerEmail
中存在重复项时,我希望我的Fraud
列具有空值
customer_email
在两个数据帧中都不是唯一的
电流输出:
customer_Email ID Fraud
name_0 0 False
name_1 1 True
name_2 2 True
name_3 3 True
name_4 4 False
name_1 5 True
name_2 0 True
name_1 1 True
name_3 2 True
预期产出:
customer_Email ID Fraud
name_0 0 False
name_1 1 True
name_2 2 True
name_3 3 True
name_4 4 False
name_1 5 N/A
name_2 0 N/A
name_1 1 N/A
name_3 2 N/A
给出:
“当CustomerMail中存在重复项时,希望我的欺诈列具有空值。”
因此,在预期的输出中,您忘记在
customerEmail
中添加name_4
,因为它也是重复的下面呢?(假设
customer_email
在df2中是唯一的):输出:
相关问题 更多 >
编程相关推荐