当前位置:网站首页>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
边栏推荐
- ArcGIS batch export layer script
- Naacl2022: (code practice) good visual guidance promotes better feature extraction, multimodal named entity recognition (with source code download)
- qt下多个子控件信号槽绑定方法
- 使用 Abp.Zero 搭建第三方登录模块(二):服务端开发
- transformers DataCollatorWithPadding类
- Unity uses skybox panoramic shader to make panorama preview. There is a gap. Solution
- Excel-VBA 快速上手(二、条件判断和循环)
- Attention meets Geometry:几何引导的时空注意一致性自监督单目深度估计
- GDAL grid data types and their type codes
- fileinput.js php,fileinput
猜你喜欢

Electron

PostGIS create spatial database

赠书 | 《认知控制》:我们的大脑如何完成任务?

Combat readiness mathematical modeling 32 correlation analysis 2

The JVM outputs GC logs, causing the JVM to get stuck. I am stupid

【云原生】 ”人人皆可“ 编程的无代码 iVX 编辑器

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

Pychar remotely connects to the server to run code

【 Native cloud】 Éditeur ivx Programmable par tout le monde

Attention meets Geometry:几何引导的时空注意一致性自监督单目深度估计
随机推荐
2021-10-29 atcoder ABC157——B - Bingo
Excerpt from three body
C语言刷题随记 —— 乒乓球比赛
【 Native cloud】 Éditeur ivx Programmable par tout le monde
A remove the underline from the label
Numpy basic use
子查询的使用
IP certificate application process of sectigo
Caelus - full scene offline mixed Department solution
Electron
Complimentary Book Cognitive Control: how does our brain accomplish tasks?
15 bs对象.节点名称.节点名称.string 获取嵌套节点内容
R语言epiDisplay包的dotplot函数通过点图的形式可视化不同区间数据点的频率、使用by参数指定分组参数可视化不同分组的点图分布、使用cex.X.axis参数指定X轴轴刻度数值标签字体的大小
Understand the difference and use between jsonarray and jsonobject
R语言dplyr包bind_rows函数把两个dataframe数据的行纵向(竖直)合并起来、最终行数为原来两个dataframe行数的加和(Combine Data Frames)
Recent important news
扩展-Hooks
wptx64能卸载吗_win10自带的软件哪些可以卸载
备战数学建模30-回归分析2
券商经理给的开户链接办理股票开户安全吗?我想开个户