获取在另一列中不存在的列数值 pandas

huangapple go评论133阅读模式
英文:

Get column values not exist in another column pandas

问题

output\n df3\n\n| A |\n| -------- |\n|I-13875002|\n|I-13875673|

英文:

I have two dataframe df1 and df2, df1 & df2 have column "A". I want output df3 has column "A" which has values of df1 not exist on df2.

df1                 
A
I-13856942
I-13856914
I-13861633
I-13875002
I-13875673

df2

A
I-13856942
I-13856914
I-13861633

output
df3

A
I-13875002
I-13875673

答案1

得分: 2

以下是翻译好的部分:

一个可能的解决方案

df1.loc[df1.merge(df2, how='left', indicator=True)['_merge'].eq('left_only'), :]

输出

              A
3  I-13875002
4  I-13875673
英文:

A possible solution:

df1.loc[df1.merge(df2, how='left', indicator=True)['_merge'].eq('left_only'),:]

Output:

            A
3  I-13875002
4  I-13875673

huangapple
  • 本文由 发表于 2023年3月15日 18:03:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/75743162.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定