pandas 数据框,当列不相等时连接两个dt [英] Pandas Dataframe, join two dt when columns are not equal

查看:74
本文介绍了 pandas 数据框,当列不相等时连接两个dt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有两个数据表,形状相同,例如N行2列.它们具有相同的列名称一个",两个"

Assume I have two datatables, identical shape, say N rows and 2 columns. They have same columns names "One", "Two"

将第一个表称为左",然后将第二个表称为右".

Call first table "left", then call second table "right".

当一个"列中两个表的值不相等时,如何返回新的数据表" FROM "表"Left"?

How can I return a new datatable FROM table "Left", when value from two tables in column "One" are not equal?

EX:

Table "Left"
One    Two
1       2
1       2
2       3
2       5
3       6


Table "Right"
One    Two
1       2
2       2
2       3
5       5
3       8


Output Table 
One    Two
1       2
2       5

谢谢!

推荐答案

认为您需要这样做:

left[left.One.values != right.One.values]

# One   Two
#1  1     2
#3  2     5

这篇关于 pandas 数据框,当列不相等时连接两个dt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆