This is the dataset.
I want to catch the changed score rows. If the current row is different from previous row, flag current row as 1.
There are some conditions need to meet. Rows can only be compared if they have same ID_No, Date and Account_No. Therefore, this need to be group by ID_No, Date and Account_No.
I did some tries but it failed in the last two row. When the ID_No and Account_No are the same but Date is different, it flag 1 for the last row. But I want the last row flag as 0 since it shouldn't be compare with the previous row.
Below is my code so far. Hope someone can help. Will be really appreciated!
TEST = df.groupby(["ID_No",'Account_No','Date'])['score'].shift().bfill()(df['score']).astype(int)