Your code is a bit long. A better way to do it is
df['TerminatedDate'].replace({'Not_Terminated':today}, inplace=True)
If you don't want replace the old column, you could save it to new column.
df['new_col'] = df['TerminatedDate'].replace({'Not_Terminated':today})
The problem with your code is this part else df_drop['TerminatedDate'] for x
as it replaces the a cell by the entire column. It should be else x for x
.
If you want to get the difference in one single action, you would have to create a custom function and apply it row wise.
def get_dif(start,end):
if end == "Not_Terminated":
end = today
return end-start
df['new_col'] = df.apply(lambda df: get_dif(df['JoinedDate'],df['TerminatedDate'], axis=1)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…