Home > OS >  DF1 is a subset of DF2 DF3 = DF2 - DF1 that will give rows that are not same store in df3
DF1 is a subset of DF2 DF3 = DF2 - DF1 that will give rows that are not same store in df3

Time:09-10

Dataframe 1 (df1):-

  date  L120_active_cohort_logins  L120_active_cohort  percentage_L120_active_cohort_logins
        0 2022-09-01                      32679              195345                             16.728865
        1 2022-09-02                      32938              196457                             16.766010
        2 2022-09-03                      40746              197586                             20.621906
        3 2022-09-04                      33979              198799                             17.092138

Dataframe 2(df2):-

         date  L120_active_cohort_logins  L120_active_cohort  percentage_L120_active_cohort_logins
0  2022-09-01                      32677              195345                             16.728864
1  2022-09-02                      32938              196457                             16.766010
2  2022-09-03                      40746              197586                             20.621906
3  2022-09-04                      33979              198799                             17.092138

result df3 = df2 - df1 I want df2 not matching with df1 particular row to be stored in df3

output :-

date  L120_active_cohort_logins  L120_active_cohort  percentage_L120_active_cohort_logins
0  2022-09-01                      32677              195345                             16.728864

CodePudding user response:

As you need to keep only the difference, You can do it this way

df3= pd.merge(df1, df2, how='outer').drop( pd.merge(df1, df2, how='inner').index)

CodePudding user response:

reference Comparing two dataframes and getting the differences

pd.concat([df1,df2]).drop_duplicates(keep=False)
  • Related