我正在尝试比较python中数据帧的两个不同列
if abc['Company Name'] is abc1['Full Legal Business Name']:
if abc['Shop Name'] is abc1['Account Name']:
if abc['Business Contact Email'] is abc1['Email Domain'] or abc['Business Contact Email'] is abc1['Business Email'] or abc['Business Contact Email'] is abc1['Customer Service Email']:
abc['Incremental_seller']='Y'
abc1['Incremental_seller'] ='Y'
else:
abc['Incremental_seller']='N'
abc1['Incremental_seller']='N'
答案 0 :(得分:0)
由于要使用文本格式显示,因此很难想象。
但是据我了解,您想比较数据框中的两列。
如果是这样,您可以简单地使用numpy.where()
来完成。
C = numpy.where('condition', x, y)
x
和y
应该是数组。
这意味着如果条件返回C
,x
等于True
,否则返回y
。
在您的情况下:
abc['Incremental_seller'] = numpy.where((abc['Company Name'] == abc1['Full Legal Business Name']) and (abc['Shop Name'] == abc1['Account Name']) or (abc['Business Contact Email'] == abc1['Business Email']) or (abc['Business Contact Email'] == abc1['Customer Service Email']), ['Y'], ['N'])
abc1['Incremental_seller'] = numpy.where((abc['Company Name'] == abc1['Full Legal Business Name']) and (abc['Shop Name'] == abc1['Account Name']) or (abc['Business Contact Email'] == abc1['Business Email']) or (abc['Business Contact Email'] == abc1['Customer Service Email']), ['Y'], ['N'])
确保您的数据帧:abc
和abc1
具有相同的长度。