当前位置:网站首页>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
边栏推荐
- Intellij IDEA--格式化SQL文件的方法
- Practical website recommendations worth collecting for College Students
- Equation derivation: second order active bandpass filter design! (download: Tutorial + schematic + Video + code)
- The annual salary of 500000 is one line, and the annual salary of 1million is another line
- Complete diagram / Euler loop
- 子查询的使用
- Oracle ASMM和AMM
- Datasets dataset class (2)
- Excerpt from three body
- Authoritative announcement on the recruitment of teachers in Yan'an University in 2022
猜你喜欢
Leaflet load day map
【使用yarn运行报错】The engine “node“ is incompatible with this module.
VMware partial settings
[solo π] ADB connects multiple mobile phones
2022年最新贵州建筑八大员(机械员)模拟考试题库及答案
The annual salary of 500000 is one line, and the annual salary of 1million is another line
聊聊 RPA 方向的规划:简单有价值的事情长期坚持做
Server create virtual environment run code
PostGIS create spatial database
Question bank and answers of the latest Guizhou construction eight (Mechanics) simulated examination in 2022
随机推荐
R语言epiDisplay包的dotplot函数通过点图的形式可视化不同区间数据点的频率、使用by参数指定分组参数可视化不同分组的点图分布、使用cex.X.axis参数指定X轴轴刻度数值标签字体的大小
PostGIS create spatial database
Use abp Zero builds a third-party login module (I): Principles
权威发布 | 延安大学2022年教师岗位招聘公告
Informatics Olympiad 1405: sum and product of prime numbers (thinking problem)
Equation derivation: second order active bandpass filter design! (download: Tutorial + schematic + Video + code)
The annual salary of 500000 is one line, and the annual salary of 1million is another line
扩展-Hooks
券商经理给的开户链接办理股票开户安全吗?我想开个户
vmware部分设置
Excel-vba quick start (II. Condition judgment and circulation)
详解C语言编程题:任意三条边能否构成三角形,输出该三角形面积并判断其类型
Is it safe to open an account by digging money? Is there any risk?
IP certificate application process of sectigo
GDAL and opencv smooth and blur TIF images
Stream常用操作以及原理探索
Sharing ideas for a quick switch to an underlying implementation
Leaflet loading ArcGIS for server map layers
Electron
聊聊几位大厂清华同学的近况