my df looks like this:
student_id completed start_enroll end_enroll completed_date
1001 N 2013-09-03 2017-02-27 NaT
1001 Y NaT NaT 2018-02-26
1002 N 2014-09-02 2020-05-30 NaT
1003 N 2008-08-25 2012-08-10 NaT
1003 Y NaT NaT 2012-08-10
.....
Please note:
- some
student_idare repeated:- when it is repeated,
completedis eitherYorNfor each - in case of
completed=Y, there is no value forstart_enrollandend_enroll - in case of
completed=N, there is no value forcompleted_date - there will always be only at most 2 rows with same
student_idand each row will beYandNrespectively - for
student_idwith only one row,completedwill always beNand we do not need to do anything
- when it is repeated,
What I am looking for is this:
- if
student_idis repeated, then:- remove the
completed=Nrow but copy thestart_enrollandend_enrollfrom thecompleted=Nrow to the row wherecompleted=Y
- remove the
The new DF should look like this:
student_id completed start_enroll end_enroll completed_date
1001 Y 2013-09-03 2017-02-27 2018-02-26
1002 N 2014-09-02 2020-05-30 NaT
1003 Y 2008-08-25 2012-08-10 2012-08-10
.....
- if
student_idis not repeated andcompleted=Nthen we do not need to do anything
could someone please provide me some steps. Thank you!