当前位置:网站首页>获取两个dataframe的交并差集
获取两个dataframe的交并差集
2022-06-26 13:56:00 【羊羊猪】
Example
交集
df_merge = pd.merge(df1,df2,on=['id','name','number'],how='inner')
并集
# 两种方式
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)
差集
# 两种方式
# 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)
# 两种方式
# 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)
对称差集
df_diff = df1.append(df2).drop_duplicates(subset=df1.columns,keep=False,ignore_index=True)
参考来源
边栏推荐
- Never use redis expired monitoring to implement scheduled tasks!
- Experience sharing of mathematical modeling: comparison between China and USA / reference for topic selection / common skills
- BM3D in popular language
- Extended hooks
- Where do people get their top energy?
- C language | the difference between heap and stack
- Understand the difference and use between jsonarray and jsonobject
- ArcGIS batch export layer script
- Combat readiness mathematical modeling 32 correlation analysis 2
- 方程推导:二阶有源带通滤波器设计!(下载:教程+原理图+视频+代码)
猜你喜欢
随机推荐
Datasets dataset class (2)
MySQL主从复制与读写分离
Recent important news
通俗语言说BM3D
Sword finger offer 18.22.25.52 Double pointer (simple)
Build your own PE manually from winpe of ADK
VMware partial settings
How to convert data in cell cell into data in matrix
Sword finger offer 09.30 Stack
Sword finger offer 40.41 Sort (medium)
Never use redis expired monitoring to implement scheduled tasks!
A remove the underline from the label
C语言基础知识入门(大全)「建议收藏」
这才是优美的文件系统挂载方式,亲测有效
Codeforces Round #765 (Div. 2) D. Binary Spiders
Leaflet load day map
Knowledge about the determination coefficient R2 and the relationship with the correlation coefficient
fileinput. js php,fileinput
Transformers datacollatorwithpadding class
Experience sharing of mathematical modeling: comparison between China and USA / reference for topic selection / common skills