I have a challenge when applying multiple conditions in columns, never did it before and would be appreciated some help,from teh database it is required:
ID user reception_date end_date Status
0 42872 [email protected] 2022-03-30 2022-03-30 Accepted
1 42872 [email protected] 2022-03-01 2022-03-04 Returned
2 42872 [email protected] 2022-03-07 2022-03-30 In Study
3 9999 [email protected] 2022-03-07 2022-03-30 Rejected
if the ID is the same, check if in the Status column has the status of "Accepted", once verified this first requirement, check if the "end_date" of "Accepted" is greater or equal to the date of the status "In Study", if this condition is true change the status from "In Study" to "Accepted".
The expected output would be as follows:
ID user reception_date end_date Status
0 42872 [email protected] 2022-03-30 2022-03-30 Accepted
1 42872 [email protected] 2022-03-01 2022-03-04 Returned
2 42872 [email protected] 2022-03-07 2022-03-30 Accepted
3 9999 [email protected] 2022-03-07 2022-03-30 Rejected
I have tried several methods to make comparisons such as np.where
, df.loc
and tried using apply()
, however the results weren't good as I expected, I don't have much knowledge about Pandas and I am still learning, thank you very much!
CodePudding user response:
This is actually not so straightforward. You need to perform a
Please be sure to answer the question. Provide details and share your research!