【问题标题】:Compare between 2 Excel files and give difference based on key column比较 2 个 Excel 文件并根据键列给出差异
【发布时间】:2016-09-26 17:02:27
【问题描述】:

我有 2 个 excel 文件(可以转换为 CSV)。

File 1:
Last Name  First Name  id(10 digit)  email   age  course
   abc       def       1234567890    axd     00    y2k
   bcd       efg       9012345875    bxe     11    k2z
   cnn       nbc       5678912345    cxn     00    z2k

File 2:
Group_ID    email     Person_ID  Name(Last,First)
1            axd      1234567890   def,abc
             cxn      5678912345   nbc,cnn

所以我想生成一个文件,在比较 file1[id] 和 file2[Person_ID] 之后会给我结果(我也可以在 file1[email] 和 file2[email] 之间比较 Person_ID 和 email在每一行中应该是唯一的:

bcd       efg       9012345875    bxe     11    k2z

我还没有弄清楚什么和如何使用,但你可以告诉我我可以使用哪些 python df 函数。

【问题讨论】:

  • 试试这个:df1.ix[~df1['id'].isin(df2.Person_ID)]

标签: python csv pandas


【解决方案1】:

假设你将文件 1 和文件 2 读入 pandas 数据帧 df1 和 df2,

df1.loc[df1['id'] != df2['Person_ID']]

【讨论】:

    猜你喜欢
    • 2018-01-09
    • 2015-08-21
    • 2022-01-03
    • 2021-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多