Diff between two dataframes in pandas

后端 未结 5 1448
北荒
北荒 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:39

    1. Set df2.columns = df1.columns

    2. Now, set every column as the index: df1 = df1.set_index(df1.columns.tolist()), and similarly for df2.

    3. You can now do df1.index.difference(df2.index), and df2.index.difference(df1.index), and the two results are your distinct columns.

提交回复
热议问题