0

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!

hoomant
  • 455
  • 2
  • 12
alireza
  • 113
  • 6

1 Answers1

1

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']
hoomant
  • 455
  • 2
  • 12