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

发布于 2025-01-21 09:41:14 字数 727 浏览 1 评论 0原文

我的任务是找出为总线充电的时间,而充电类型= 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

这是从中的输出: 在此处输入图像描述

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

征﹌骨岁月お 2025-01-28 09:41:14

您可以使用DateTime模块来找出2个事件之间的时间:

from datetime import datetime

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

total = end - start

seconds_elapsed = total.total_seconds()

print (seconds_elapsed)

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文