how to subtract two Solar Hijri column date

105 Views Asked by At

I have a data frame like this:

index ft rt
0 1401/04/21 13:36:00 1401/04/21 13:09:16
1 1401/04/21 14:00:00 1401/04/21 13:00:00

these column dates are based on "the Solar Hijri calendar". and when I use

type()

for values in these columns, it shows me that they are as strings. how can I subtract these columns ?! (ft - rt) Any help would be greatly appreciated!

1

There are 1 best solutions below

0
hoomant On

You can use the jdatetime package to convert your strings into datetime objects:

import jdatetime

df['ft'] = df['ft'].apply(lambda x: jdatetime.datetime.strptime(x, '%Y/%m/%d %H:%M:%S'), axis=1)
df['rt'] = df['rt'].apply(lambda x: jdatetime.datetime.strptime(x, '%Y/%m/%d %H:%M:%S'), axis=1)

df['sub'] = df['ft'] - df['rt']