I have a data frame as below;
ID | Transaction_Date | Label |
---|---|---|
101 | Null | Group1 |
101 | 2021-12-29 | Group2 |
102 | 2021-01-01 | Group1 |
102 | 2021-11-01 | Group2 |
103 | 2021-11-15 | Group3 |
104 | 2021-12-15 | Group2 |
105 | 2021-01-15 | Group1 |
Then I have a list of IDs. For example, [101, 102, 103]
I would like to search IDs in the list, then update the label column based on the comparison with Transaction_Date.
So, If an ID is not found in the list AND Transaction_Date > Today
, THEN update that ID's Label column to Group5
, otherwise, mark as Group6
.
This is can be done with a for-loop but I was trying to find a better way.