I am trying to subtract the date of today of a date set in a pandas dataframe.
Example data frame :
8 Emma Mike 1 2018/5/21 1654160303.597019
12 Emma Mike 3 2018/6/03 1654160303.597019
13 Emma Mike 1 2018/8/03 1654160303.597019
16 Emma Mike 2 2019/2/8 1654160303.597019
17 Emma Mike 2 2019/2/13 1654160303.597019
19 Emma Mike 2 2019/3/18 1654160303.597019
This is my code:
df_transactions['month'] = df_transactions['date'].str.split('/').str[1].astype(int) #select only one column of the dataframe
month = df_transactions['month'] #define value month
time_difference = pd.to_datetime(month) - pd.Timestamp.now().normalize() #calculate time difference
print(time_difference)
However, the results are as follows:
8 -19145 days +00:00:00.000000005
9 -19145 days +00:00:00.000000005
10 -19145 days +00:00:00.000000006
11 -19145 days +00:00:00.000000006
12 -19145 days +00:00:00.000000006
13 -19145 days +00:00:00.000000008
14 -19145 days +00:00:00.000000001
something is going wrong in the subtraction, no clue what. Thanks!