如何比较python中两个不同数据框的列?

时间:2019-08-23 15:21:22

标签: python pandas

我正在尝试比较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'

1 个答案:

答案 0 :(得分:0)

由于要使用文本格式显示,因此很难想象。

但是据我了解,您想比较数据框中的两列。

如果是这样,您可以简单地使用numpy.where()来完成。

C = numpy.where('condition', x, y)

xy应该是数组。

这意味着如果条件返回Cx等于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'])

确保您的数据帧:abcabc1具有相同的长度。