i have a pandas data frame df.drop which has two date columns Joined Date and Terminated Date. i want to get the difference(in days) between terminated date and joined date. but there is a text value in terminated date 'Not terminated'. hence i tried to convert it in to today's date and then get the difference. below is the code which i tried for convertion
import time
today=time.strftime(("%Y-%m-%d"))
df_drop['TerminatedDate_new'] = [today if x=='Not_Terminated' else df_drop['TerminatedDate'] for x in df_drop['TerminatedDate']]
although it gives correct answer(today) for 'Not_Terminated' rows, for date values, it gives entire df_drop['TerminatedDate'] column instead of the existing date(else part of the code).
how do i change it so that it select the same raw and give the existing date value?
also is there easy method to get the difference without separably calculating df_drop['TerminatedDate_new']
See Question&Answers more detail:os