【发布时间】:2019-06-21 21:51:20
【问题描述】:
我正在将 Blf 文件转换为 Tab 分隔文件。我能够从下面列表中的文件中提取所有有用的信息。我想计算一列中时间戳值之间的差异。到目前为止,请找到我的代码:
import can
import csv
import datetime
import pandas as pd
filename = open('C:\\Users\\shraddhasrivastav\\Downloads\\BLF File\\output.csv', "w")
log = can.BLFReader('C:\\Users\\shraddhasrivastav\\Downloads\\BLF File\\test.blf')
# print ("We are here!")
log_output = []
for msg in log:
msg = str(msg).split()
#print (msg)
data_list = msg[7:(7 + int(msg[6]))]
log_output_entry = [(msg[1]), msg[3], msg[6], " ".join(data_list), msg[-1]]
log_output_entry.insert(1, 'ID=')
test_entry = " \t ".join(log_output_entry) # join the list and remove string quotes in the csv file
filename.write(test_entry + '\n')
df = pd.DataFrame(log_output)
df.columns = ['Timestamp', 'ID', 'DLC','Channel']
filename.close() # Close the file outside the loop
到目前为止我得到的输出如下:
在我的第一列下,我想要时间戳值之间的差异(示例 - 第 2 行值 - 第 1 行时间戳值......第 4 行时间戳值 - 第 3 行时间戳值......等等...... . 我应该在我的代码中添加什么来实现这一点?
下面是我希望文件的时间戳字段看起来如何的屏幕截图。 (计算连续行之间的差异)
【问题讨论】:
-
我编辑了您的格式,我相信您最后的部分问题已格式化到您的代码中,请检查它现在是否正确。
标签: python python-3.x pandas filenames python-datetime