比较两个不同的csv文件中的两列

时间:2019-04-05 07:02:25

标签: python

正在执行的任务:我正在尝试比较两个不同的csv文件中的两个不同的列值,并尝试在该列的值匹配的情况下打印整行。

问题:该行正在以受限格式打印。

  orgID1  appId1         ConSecret1
    3     VALIDATE  ...  ZbqK4MnlaFQruL9d

[1行x 4列]

所有4列均未显示。

import pandas as pd
df1 = pd.read_csv('Names1.csv')
df2 = pd.read_csv('Names2.csv')
s1 = set(df1['ConSecret1'])
s2 = set(df2['ConSecret2'])
set1 = s1.intersection(s2)
final_list1 = list(set1)
print("Common Consumer Secret is : ", final_list1)

if len(final_list1) > 0:
    for p in final_list1:
        dfA = pd.read_csv("Names1.csv", sep=",")
        dfB = pd.read_csv("Names2.csv", sep=',')
        print("The orgs with common secret in Landscape1 are: \n", dfA[dfA["ConSecret1"] == p])
        print("The orgs with common secret in Landscape2 are: \n", dfB[dfB["ConSecret2"] == p])
else:
    print("No common consumer secret found")

预期输出:

C:\Users\I332512\PycharmProjects\Test01\venv\Scripts\python.exe C:/Users/I332512/PycharmProjects/Test01/Compare_Keys.py
Common Consumer Secret is :  ['ZbqK4MnlaFQruL9d', 'hAzBPBAbGNDY8KEE']
The orgs with common secret in Landscape1 are: 
      orgID1  appId1   conKey1      ConSecret1
3  VALIDATE  xyz        pqr     ZbqK4MnlaFQruL9d

[1 rows x 4 columns]

实际输出:

C:\Users\I332512\PycharmProjects\Test01\venv\Scripts\python.exe C:/Users/I332512/PycharmProjects/Test01/Compare_Keys.py
Common Consumer Secret is :  ['ZbqK4MnlaFQruL9d', 'hAzBPBAbGNDY8KEE']
Common Consumer Key is : []
The orgs with common secret in Landscape1 are: 
      orgID1  ...        ConSecret1
3  VALIDATE  ...  ZbqK4MnlaFQruL9d

[1 rows x 4 columns]

0 个答案:

没有答案