I've got a pandas dataframe 'A' with a column 'date' containing timestamps in the following format:
2020-06-09 13:30:11.359497
I need to calculate the time difference between every line and the previous in minutes. I've tried Timedelta, shift and diff.
from datetime import datetime
import time
t1 = '09/06/2020 13:30:11.359497'
t2 = '10/06/2020 09:30:12.352452'
# convert t1, t2 to type datetime
date_time_t1 = datetime.strptime(t1, '%d/%m/%Y %H:%M:%S.%f')
date_time_t2 = datetime.strptime(t2, '%d/%m/%Y %H:%M:%S.%f')
# convert date_time_t1, date_time_t2 to Unix timestamp
timestamp_1 = time.mktime(date_time_t1.timetuple())
timestamp_2 = time.mktime(date_time_t2.timetuple())
# the difference in minutes
print(int(timestamp_2 - timestamp_1) / 60)