简体   繁体   中英

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? 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

You can use the datetime module to figure out the amount of time between 2 events:

from datetime import datetime

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

total = end - start

seconds_elapsed = total.total_seconds()

print (seconds_elapsed)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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