Let's say I have a pd.DataFrame that looks as such:
id col1_a col1_b col2_a col2_b
1 x x 2 3
2 z d 4 5
3 y y 9 9
4 p p 8 1
What this dataframe represents is a 2 dataframe (df_a, df_b) column by column comparison.
I am trying to get a dataframe that highlights and finds the columns that contain those differences as such:
id col1_a col1_b col2_a col2_b diff
1 x x 2 3 col2
2 z d 4 5 col1,col2
3 y y 9 9 None
4 p p 8 1 col2
How can I achieve something like this without having to doubly traverse through the cols and rows.
I know I can achieve this by doing something similar (not tested):
for col_ptr1 in df.columns:
for col_ptr2 in df.columns:
for idx, row in df.iterrows():
if col_ptr1.strip('_a') == col_ptr2.strip('_b'):
blah blah blah...
This is super ugly. I wonder if there is a more pandas style approach to this.