其他分享
首页 > 其他分享> > Pandas并集差集交集与isin

Pandas并集差集交集与isin

作者:互联网

并集:

# 实现1
df_union = pandas.concat([df1, df2])
# 实现2
df_union = pandas.merge(df1, df2, on=df1.columns.to_list(), how="outer")

差集:

# 实现1
df_diff = df_union.append(df1).drop_duplicates(subset=df_union.columns.to_list(), keep=False)
# 实现2
df_diff = df_union[~df_union.isin(df1)].dropna(how="all")

交集:

# 实现1
df_in = pandas.merge(df_union, df1, on=df1.columns.to_list())
#实现2
df_in = df_union[df_union.isin(df1)].dropna(how="all")

标签:how,df,df1,差集,pandas,union,isin,Pandas,columns
来源: https://blog.csdn.net/fran_c/article/details/120716907