I have a below dataframe
id action
================
10 CREATED
10 111
10 222
10 333
10 DONE
10 222
10 UPDATED
777 CREATED
10 333
10 DONE
I would like to create a new column "check" that would be based on data in previous rows in dataframe:
- Find cell in action column = "DONE"
- Search for the first CREATED or UPDATED with the same id in previous rows, before DONE. In case its CREATED then put C in case UPDATED put U.
Output:
id action check
================
10 CREATED
10 111
10 222
10 333
10 DONE C
10 222
10 UPDATED
777 CREATED
10 333
10 DONE U
I tried to use multiple if conditions but it did not work for me. Can you pls help?
Aucun commentaire:
Enregistrer un commentaire