I have two pandas dataframes
df1
jon,12,NewYork
jon,12,NewYork
james,14,LA
df2
jon,12,NewYork
james,14,LA
I want to compare them and get the difference as below
deltaDF
jon,12,NewYork
I tried pd.concat([df1,df2,df2],axis=0,sort=False).drop_duplicates(keep=False)
This works fine when there are not duplicates but doesn't give difference when one of the dataframe contains duplicates and other dataframe has single entry. I have also tried the solutions mentioned in Python Pandas - Find difference between two data frames but that is also returning empty dataframe in this case
Similar questions
I think this is not a duplicate question because an answer given to this question returning empty dataframe for the above scenario.
Edit
People are telling that this is not possible. Can we do something like this:
Add a column giving the count of occurrence of each row
Convert above df1 to
jon,12,NewYork,2
james,14,LA,1
Convert above df2 to
jon,12,NewYork,1
Now I can use all columns as index and subtract the last column.