当前位置:网站首页>Get the intersection union difference set of two dataframes
Get the intersection union difference set of two dataframes
2022-06-26 14:51:00 【Sheep sheep pig】
Example

intersection

df_merge = pd.merge(df1,df2,on=['id','name','number'],how='inner')

Combine

# Two ways
df_union = pd.merge(df1,df2,on=['id','name','number'],how='outer')
df_union2 = df1.append(df2).drop_duplicates(subset=df1.columns,keep='first',ignore_index=True)

Difference set

# Two ways
# df1-df2
df_diff1 = df1.append(df1.append(df2)).drop_duplicates(subset=df1.columns,keep=False,ignore_index=True)
df_diff1 = pd.concat([df1,df1,df2]).drop_duplicates(keep=False)

# Two ways
# df2 - df1
df_diff2 = df2.append(df2.append(df1)).drop_duplicates(subset=df2.columns,keep=False,ignore_index=True)
df_diff2 = pd.concat([df1,df2,df2]).drop_duplicates(keep=False)

Symmetric difference set

df_diff = df1.append(df2).drop_duplicates(subset=df1.columns,keep=False,ignore_index=True)

Reference source
pandas.DataFrame.drop_duplicates Official documents
pandas.merge Official documents
边栏推荐
- oracle11g数据库导入导出方法教程[通俗易懂]
- 登录认证服务
- datasets Dataset类(2)
- Atcoder bit operation & Conclusion + formula derivation
- Unity uses skybox panoramic shader to make panorama preview. There is a gap. Solution
- Stream常用操作以及原理探索
- 手机股票注册开户安全吗,有没有什么风险?
- 聊聊 RPA 方向的规划:简单有价值的事情长期坚持做
- Electron
- Naacl2022: (code practice) good visual guidance promotes better feature extraction, multimodal named entity recognition (with source code download)
猜你喜欢

ArcGIS batch render layer script

Mark: unity3d cannot select resources in the inspector, that is, project locking

Use abp Zero builds a third-party login module (II): server development

Common evaluation indexes of classification model -- confusion matrix and ROC curve
![[cloud native] codeless IVX editor programmable by](/img/10/7c56e46df69be6be522a477b00ec05.png)
[cloud native] codeless IVX editor programmable by "everyone"

Notes on writing questions in C language -- table tennis competition

一篇抄十篇,CVPR Oral被指大量抄袭,大会最后一天曝光!

【雲原生】 ”人人皆可“ 編程的無代碼 iVX 編輯器

Leaflet loading ArcGIS for server map layers

View touch analysis
随机推荐
【async/await】--异步编程最终解决方案
C语言刷题随记 —— 乒乓球比赛
710. random numbers in the blacklist
[cloud native] codeless IVX editor programmable by "everyone"
fileinput.js php,fileinput
Extended hooks
Caelus - full scene offline mixed Department solution
H5关闭当前页面,包括微信浏览器(附源码)
MHA high availability coordination and failover
K gold Chef (two conditions, two points and difference)
Deploy the flask environment using the pagoda panel
Numpy基本使用
券商经理给的开户链接办理股票开户安全吗?我想开个户
oracle11g数据库导入导出方法教程[通俗易懂]
feil_uVission4左侧工目录消失
MHA高可用配合及故障切换
15 bs对象.节点名称.节点名称.string 获取嵌套节点内容
2022年最新贵州建筑八大员(机械员)模拟考试题库及答案
Solution to the upper limit of TeamViewer display devices
Complimentary Book Cognitive Control: how does our brain accomplish tasks?