I want to compare column1 and column2 and get the unique values causing difference to be detected from column1 (ignoring NaN). So in this case, I should get answer to be tb, 2 and rexth.Its comparing first column to second one
Also, can we create and store the result in another column?
df['diff'] = df['column1'].groupby(df['column2']).unique()
Result
index column1 column2 diff
1. John John-'tb' -tb
2. Dec-1 Dec-2 2
3. Teb12 rexth rexth
4. dx-tyr nan nan
5. [fever]='1' nan nan
6. [dsc]= rx2 NA NA or leave it empty("")
7. fv=56 fv=rt276 rt276
Code can be in either R or Python. I dont mind