Надеюсь, это поможет вам найти решение.df2
- это кадр данных с пересечением двух других, основанный на трех одинаковых столбцах.cleared_df
- это начальное значение df
, за исключением пересечения.
#Replicating the question's input
d={1:[1,1,1],2:[1,0,0],3:[0,1,0],4:[0,0,0],5:[0,0,1]}
d1={1:[1,1],2:[1,0],5:[0,1]}
df = pd.DataFrame(data=d)
df1 = pd.DataFrame(data=d1)
#Make df with the same records on 1,2,5
df2=pd.merge(df, df1, on=[1,2,5], how='inner')
#Concat the initial df with the one with the same records, then drop the duplicates
cleared_df=pd.concat([df, df2]).drop_duplicates(keep=False)