【问题标题】:Comparing data of two row in single dataframe比较单个数据框中两行的数据
【发布时间】:2018-08-15 09:32:34
【问题描述】:
MasterAgreementId   MasterAgreementType Data Source Break Type
11000002    ISDA    Source System   
11000002    ISDA    CMRS    
11000043    ISDA    CMRS    
11000049    ISDA    Source System   
11000049    ISDA    CMRS    
1451057679  ISDA    Source System   

我有一个包含这样的数据的数据框。我想使用 MasterAgreementId 作为比较键并希望输出如下:

MasterAgreementId   MasterAgreementType Data Source Break Type
11000002    ISDA    Source System   Identical
11000002    ISDA    CMRS    Identical
11000043    ISDA    CMRS    Difference
11000049    ISDA    Source System   Identical
11000049    ISDA    CMRS    Identical
1451057679  ISDA    Source System   Difference

我想在没有迭代的情况下实现这一点。

【问题讨论】:

  • 你想和它自己比较一下吗?你是怎么到达IdenticalDifference的?
  • 到目前为止你尝试过什么?你在用熊猫吗?你能提供一个minimal reproducible example吗?

标签: python


【解决方案1】:

通过使用 MasterAgreementid,

我使用重复来填充另一列,该列给我每一行的假值和真值,现在我正在尝试计算它们的相同和差异

【讨论】:

  • 根据@jpp 评论,请阅读 MCVE,这不是答案,而是评论。你还想看看 np.which 或 shift()。
  • 用于解决问题陈述的代码 df['Matching Key'] = df.duplicated(['MasterAgreementId'], keep=False) df.loc[df_Source_FileName['Matching Key'] = = True , '中断类型'] = '相同'
  • 之前的问题已经解决了,现在想补充一下之前的问题,
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-06-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-17
  • 1970-01-01
相关资源
最近更新 更多