df1: | A | B | C |ID | |---|---|---|---| | 1 | 5 | 2 | Y | | 4 | 6 | 4 | Z |
df2: | A | B | C |ID | |---|---|---|---| | 2 | 1 | 2 | Y | | 4 | 6 | 4 | Z |
Merged: | case | A | B | C |ID | |------|---|---|---|---| |before| 1 | 5 | 2 | Y | |before| 4 | 6 | 4 | Z | |after | 2 | 1 | 2 | Y | |after | 4 | 6 | 4 | Z |
desired pivot for column A: |ID |before|after| |- |------|-----| | Y | 1 | 2| | Z | 4 | 4|
I want to use a for loop to create a pivot table for each column in dfs 1 and 2. The rows of these pivots will be the ID, the columns will be 'case'.
I would like to create a new df for each column's pivot table using a for loop.
Later, I will drop the rows in each pivot table where the before and after values are the same (only keeping the rows where they are different).