提前合并熊猫数据框

时间:2020-06-15 17:47:44

标签: python python-3.x pandas dataframe merge

我有几个希望合并的熊猫数据框,但是:

  1. 它们没有共同的唯一ID;
  2. 某些条目引用相同的事件,但在不同的数据帧上使用不同的名称;
  3. 通过每个数据帧中的5列的组合来确保它们在同一条目中的方式,其中每列中的一列(在日期时间中)(未在其中一个中排序)。

该如何处理?

例如:

DF1:
date        name        observation    measurement    result    notes
2016-08-12  this thing  another        1              3         alright
2016-08-12  thing too   bother         1              3         good
2016-08-13  another     not great      0              0         weird
...
2017-12-29  else        this thing     2              2         no way
2018-01-04  not great   bother         4              1         lucky
2018-01-04  another     this thing     1              1         good

DF2:
Date        col1       col2            alpha          delta    stuff
2016-08-12  this       another         1              3        87
2016-08-12  thing too  bother          1              3        42
2018-04-28  not else   this            2              2        31
2017-12-29  not else   this            2              2        90
2018-01-04  another    this            1              1        13
2016-08-13  another    not great       0              0        23
...

所需结果:

mergedDF:
date        name        observation    measurement    result    notes    stuff
2016-08-12  this thing  another        1              3         alright  87
2016-08-12  thing too   bother         1              3         good     42
2016-08-13  another     not great      0              0         weird    23
...
2017-12-29  else        this thing     2              2         no way   90
2018-01-04  not great   bother         4              1         lucky    0     
2018-01-04  another     this thing     1              1         good     13

预先感谢

0 个答案:

没有答案