简体   繁体   English

我如何找到多个事件的两个时间之间的持续时间?

[英]How do i find the duration between two timings for multiple events?

My task is to find out how long the bus is charged for, and when charging type = 1, it means that the charger is plugged in. How do i find the duration from this?我的任务是找出公共汽车充电了多长时间,当充电类型 = 1 时,这意味着充电器已插入。我如何从中找到持续时间? Also i need to find out the charging frequency, is there a way i can do that too?我还需要找出充电频率,我也可以这样做吗?

Here is the code currently:这是目前的代码:

#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

and here is the output from it: enter image description here这是其中的 output:在此处输入图片描述

You can use the datetime module to figure out the amount of time between 2 events:您可以使用 datetime 模块计算出两个事件之间的时间量:

from datetime import datetime

start = datetime.now()
#Func here
end = datetime.now()

total = end - start

seconds_elapsed = total.total_seconds()

print (seconds_elapsed)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM