差集交集

两个df对象,要获取这两个df对象的交集和差集
取交集
inner_df = pd.merge(df1, df2, how='inner') ## 计算df1=df2的部份

left_df = pd.merge(df1, df2, how='left') ## df1部分

right_df = pd.merge(df1, df2, how='right') ## df2部分

outer_df = pd.merge(df1, df2, how='outer') ## 取合集:df1和df2所有数据的集合

取差集
利用了drop_duplicates
df1-df2
df = pd.concat([df1, df2, df2]).drop_duplicates(subset=['filed_name', 'filed_type'], keep=False)
df2-df1
df = pd.concat([df2, df1, df1]).drop_duplicates(subset=['filed_name', 'filed_type'], keep=False)

等同于
fileds_df = df1.append(df2).drop_duplicates(subset=['filed_name', 'filed_type'], keep=False)
fileds_df = df2.append(df1).drop_duplicates(subset=['filed_name', 'filed_type'], keep=False)

上一篇:MallBuilder逻辑后门(复现)


下一篇:C中的struct,union,Bit Filed以及内存对齐