计算同一列中连续行之间的差异

Calculate difference between consecutive rows within a same column

我正在尝试计算 Timestamp 列中连续行之间的差异。根据我的逻辑,我收到以下错误:

我的日志变量中包含如下数据:

['Timestamp:', '1546626931.138813', 'ID:', '0764', 'S', 'DLC:', '8', 00', '00', '00', '00', '00', '00', '00', '00', 'Channel:', '0']
['Timestamp:', '1546626931.138954', 'ID:', '0365', 'S', 'DLC:', '8', 00', '00', '00', '80', 'db', '80', 'a2', '7f', 'Channel:', '1']
['Timestamp:', '1546626931.139053', 'ID:', '0765', 'S', 'DLC:', '8', '0d', '0f', '00', '00', 'fd', '0e', '00', '01', 'Channel:', '1']
['Timestamp:', '1546626931.139289', 'ID:', '0766', 'S', 'DLC:', '8', 'fd', '0e', '02', '01', 'fc', '0e', '03', '01', 'Channel:', '1']
.
.
.
.

密码是:

import can
import csv
import datetime
import pandas


filename = open('C:\Users\xyz\Downloads\BLF File\output.csv', "w")
log = can.BLFReader('C:\Users\xyz\Downloads\BLF File\test.blf')

log_output = []
timestamp = []                        #Variable to store timestamps from blf file
time_del = []                         #Variable to store time difference
print('We are here 1')
for time in log:
    time = str(time).split()
    timestamp.append(float(time[1]))
    # print(timestamp)

print("we are here 2")
count = 0

for i in range(len(timestamp)-1):
    delta_float= timestamp[count+1] - timestamp[count]
    count = count + 1
print(delta_float)

我得到以下输出:

We are here 1
we ar here 2
0.00022101402282714844
0.0002288818359375
0.00021910667419433594
0.00024199485778808594
.
.
.
.

为什么我在 delta_float 中没有得到正确的差异?根据我在日志变量中的值,我应该得到类似下面的东西,对吗?

0.141
0.99
0.236
.
.

为什么这个逻辑没有给出同一列中连续行之间的差异 Timestamp

你只打印一个值,因为你只有一个 print 语句(不包括 "we are here" 语句),它不在循环体中,它正在打印一个标量值。您必须至少更改其中一项,可能是第二项才能执行您想要的操作,以使其打印多个值。