Diff between two dataframes in pandas

后端 未结 5 1432
北荒
北荒 2020-12-17 05:04

I have two dataframes both of which have the same basic schema. (4 date fields, a couple of string fields, and 4-5 float fields). Call them df1 and df2

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-17 05:40

    Try this:

    diff_df = pd.merge(df1, df2, how='outer', indicator='Exist')
    
    diff_df = diff_df.loc[diff_df['Exist'] != 'both']
    

    You will have a dataframe of all rows that don't exist on both df1 and df2.

提交回复
热议问题