I am facing issues in comparing two Dataframes of different lengths. Below is the issue:
df1 =
emp_id emp_name counts
1 sam 0
2 joe 0
3 john 0
df2 =
emp_id emp_name counts
1 sam 0
2 joe 0
2 joe 1
3 john 0
My Expect output is:
Expected_output_df =
df1 df2
empId emp_name emp_id emp_name
1 sam 1 sam
2 joe 2 joe
NaN NaN 2 joe
3 john 3 john
whereas am getting output as below:
actual_output_df =
df1 df2
empId emp_name emp_id emp_name
1 sam 1 sam
2 joe 2 joe
3 john 2 joe
NaN NaN 3 john
Please Note that my expectation is not to merge the 2 dataframes into one but I would like to concat two dataframes side by side and highlight the differences in such a way that, if there is a duplicate row in one df, example df2, the respective row of df1 should show as NaN/blank/None any Null kind of values Below is what I have followed:
- I tried to use
df.Merge()
to get the mismatched rows first which resulted indf1
anddf2
. pd.concat()
the left-only and right-only rows. but my final output is not as expected. The main issue I have is in pd.concat. am able to get the differences in step 1. But after I concat, I am not able to move the duplicate rows one row down.
Can anyone please help me on this? Thanks in advance