Issue
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
Solution
This worked for me
pd_df1 = pd.merge(click_df1, click_df2, on="L120_active_cohort_logins", how='outer', indicator='Exist')
pd_df1 = pd_df1.loc[pd_df1['Exist'] != 'both']
final_df = pd_df1[pd_df1['Exist'] == 'right_only'][['date_y','L120_active_cohort_logins','L120_active_cohort_y','percentage_L120_active_cohort_logins_y']]
columns = ['date','L120_active_cohort_logins','L120_active_cohort','percentage_L120_active_cohort_logins']
final_df.columns = columns
Answered By - vaibhav
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.