当前位置:网站首页>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
边栏推荐
- 710. 黑名单中的随机数
- Intellij IDEA--格式化SQL文件的方法
- 【 Native cloud】 Éditeur ivx Programmable par tout le monde
- wptx64能卸载吗_win10自带的软件哪些可以卸载
- Question bank and answers of the latest Guizhou construction eight (Mechanics) simulated examination in 2022
- Login authentication service
- Correlation of XOR / and
- View touch analysis
- 15 bs对象.节点名称.节点名称.string 获取嵌套节点内容
- 手机股票注册开户安全吗,有没有什么风险?
猜你喜欢

VMware partial settings

ArcGIS batch export layer script

Combat readiness mathematical modeling 32 correlation analysis 2

Detailed explanation of C language programming problem: can any three sides form a triangle, output the area of the triangle and judge its type

Server create virtual environment run code

Authoritative announcement on the recruitment of teachers in Yan'an University in 2022

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

C语言刷题随记 —— 乒乓球比赛

The engine "node" is inconsistent with this module

Electron
随机推荐
启动Redis报错:Could not create Server TCP listening socket *:6379: bind: Address already in use–解决办法
R语言dplyr包bind_rows函数把两个dataframe数据的行纵向(竖直)合并起来、最终行数为原来两个dataframe行数的加和(Combine Data Frames)
ArcGIS secondary development method - layer related operations (add, modify)
Use abp Zero builds a third-party login module (II): server development
R语言epiDisplay包的dotplot函数通过点图的形式可视化不同区间数据点的频率、使用by参数指定分组参数可视化不同分组的点图分布、使用cex.X.axis参数指定X轴轴刻度数值标签字体的大小
710. 黑名单中的随机数
Equation derivation: second order active bandpass filter design! (download: Tutorial + schematic + Video + code)
Is it safe to open an online stock account? Somebody give me an answer
fileinput. js php,fileinput
Sharing ideas for a quick switch to an underlying implementation
GDAL and opencv smooth and blur TIF images
聊聊几位大厂清华同学的近况
Oracle11g database import and export method tutorial [easy to understand]
'教练,我想打篮球!' —— 给做系统的同学们准备的 AI 学习系列小册
Sectigo的IP证书申请流程
One copy ten, CVPR oral was accused of plagiarizing a lot, and it was exposed on the last day of the conference!
wptx64能卸载吗_win10自带的软件哪些可以卸载
备战数学建模31-数据插值与曲线拟合3
Informatics Olympiad 1405: sum and product of prime numbers (thinking problem)
C语言基础知识入门(大全)「建议收藏」