I have two dataframes, df1 & df2. They have the same column names and usually the same column values. I need to isolate the rows where the value in the column was changed, and add a column to signify what the previous value was.
In the example below, the number of actions for Nancy changes between df1 and df2. I want to create a new dataframe with just that row, even though a new row for Mary was added to df2.
df1:
| Name | Action | Number of Actions |
|---|---|---|
| Stacy | Action1 | 32 |
| Nancy | Action2 | 67 |
| Emily | Action3 | 89 |
| Abby | Action2 | 9 |
df2:
| Name | Action | Number of Actions |
|---|---|---|
| Stacy | Action1 | 32 |
| Nancy | Action2 | 75 |
| Emily | Action3 | 89 |
| Abby | Action2 | 9 |
| Mary | Action1 | 43 |
Expected Output (as a dataframe):
| Name | Action | Number of Actions | Previous Value |
|---|---|---|---|
| Nancy | Action2 | 75 | 67 |