python - 如何找到从包含时间的数据集中导入的时间差异
问题描述
我想减去我从tt.txt
文件中导入的两个时间实例。但参数 tostrptime
必须是string
('%H.%M' 格式)。我怎么解决这个问题?
我的代码:
import numpy as np
import matplotlib.pyplot as plt
from datetime import datetime
data = np.genfromtext('tt.txt', delimiter= ' ')
sn = data[ :, ][ :,0]
dt = data[ :, ][ :,1] # dt = depature time, 2nd column of table
at = data[ :, ][ :,2] # at = arrival time, 3rd column of table
str1 = dt[3]
str2 = at[3]
start = datetime.strptime(str1, '%H.%M')
end = datetime.strptime(str2, '%H.%M')
c = end - start
print(c)