我如何找到多个事件的两个时间之间的持续时间?
How do i find the duration between two timings for multiple events?
我的任务是找出公交车充电了多长时间,当charging type = 1 时,表示充电器已插入。我如何从中找到持续时间?我还需要找出充电频率,有什么办法可以做到吗?
当前代码如下:
#Duration loop
foundEnd = False
for i in range(len(dfDur01Mar22)):
#only display bus 'SG3079S'
if dfDur01Mar22.iloc[i,1] == 'SG3079S':
#print 'end' when first '0' appears
if not foundEnd and dfDur01Mar22.iloc[i,2] == 0:
print('end')
foundEnd = True
#if charging type is 1
elif dfDur01Mar22.iloc[i,2] == 1:
print(dfDur01Mar22.iloc[i,0],dfDur01Mar22.iloc[i,1],dfDur01Mar22.iloc[i,2])
foundEnd = False
这是它的输出:
enter image description here
您可以使用日期时间模块计算出两个事件之间的时间量:
from datetime import datetime
start = datetime.now()
#Func here
end = datetime.now()
total = end - start
seconds_elapsed = total.total_seconds()
print (seconds_elapsed)
我的任务是找出公交车充电了多长时间,当charging type = 1 时,表示充电器已插入。我如何从中找到持续时间?我还需要找出充电频率,有什么办法可以做到吗?
当前代码如下:
#Duration loop
foundEnd = False
for i in range(len(dfDur01Mar22)):
#only display bus 'SG3079S'
if dfDur01Mar22.iloc[i,1] == 'SG3079S':
#print 'end' when first '0' appears
if not foundEnd and dfDur01Mar22.iloc[i,2] == 0:
print('end')
foundEnd = True
#if charging type is 1
elif dfDur01Mar22.iloc[i,2] == 1:
print(dfDur01Mar22.iloc[i,0],dfDur01Mar22.iloc[i,1],dfDur01Mar22.iloc[i,2])
foundEnd = False
这是它的输出: enter image description here
您可以使用日期时间模块计算出两个事件之间的时间量:
from datetime import datetime
start = datetime.now()
#Func here
end = datetime.now()
total = end - start
seconds_elapsed = total.total_seconds()
print (seconds_elapsed)