大熊猫合并,不考虑共同项目

时间:2019-11-04 09:23:54

标签: python pandas merge

美好的一天

我希望以SQL方式合并大熊猫,使我从集合 A 中获得项目,而这些项目不在集合 B 中。熊猫如何做到这一点?

select * from a 
  left join 
 b
 on a.key1 = b.key1 and a.key2= b.key2
 where b.key1 is NULL or b.key2 is NULL

来自javarevisited.blogspot.com的Sql示例。

我发现的最接近的是another SO question,但感觉像“ unPandas”,并且由于有多个连接键而变得很长。

我最好的“解决方法”:在 A B 上进行内部联接,然后从A中删除常见元素。类似于:

 common = pd.merge(a, b, how='inner', left_on='key', right_on='key')
 new_a = a[~a['key']isin(common['key']]

那么,有什么更巧妙的方法可以做到这一点?

1 个答案:

答案 0 :(得分:0)

您要合并,但不包括联接。

left-excluding join

看看this,上面的图片是从这个答案中获取的。

function isScrolledIntoView(el) {
      var rect = el.getBoundingClientRect();
      return (rect.middle >= 0) && (rect.bottom <= window.innerHeight);
 }


function animateGifsInScreen() {
    $('.gif').each(function(index, el) {
      if(isScrolledIntoView(el)) {
        $(el).trigger('mouseenter');
      } else {
        $(el).trigger('mouseleave');
      }
    });
}

$(document).scroll(animateGifsInScreen);