我使用asammdf或mdfreader之类的MDF文件。但是我的数据文件也是 大。因此,我想读取特定数据并制作一个数据框。
- 使用asammdf中的asammdf导入MDF的MDF数据读取器
mdfreader的情况下,存在很多错误,因为我的mdf文件是相同名称的数据,并且在重采样时遇到了一些麻烦(错误的数据输出)filename = test_t16.dat”;我的MDF数据文件
yop = MDF(文件名);使用asammdf的mdf阅读器
whl_rr = yop.get('WHL_SPD_RR');我从mdf中选择一些数据 文件(yop)
whl_rr =
invalidation_bits = {NoneType}无
master_metadata = {tuple}(“ TimeChannel”,1)
name = {str}'WHL_SPD_RR'
raw = {bool}错误
samples = {ndarray} [0。 ... 0。]
source = {NoneType}无
stream_sync = {bool}错误
timestamps = {ndarray} [240.4053 ... 2050.81525]
unit = {str}'km / h' > 我想要这样的数据框
from asammdf import MDF
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
filename = r"C:\Users\wonyo\PycharmProjects\test\test_t16.dat"
yop = MDF(filename)
signallist = [ "WHL_SPD_RR","WHL_SPD_FR", "WHL_SPD_RL","WHL_SPD_FL"]
df=[]
def group_len(yop, start, stop):
for i in range(start, stop):
if yop.get_group(i).empty != True:
if i == start:
max_len = len(yop.get_group(i).TimeChannel)
min_time = min(yop.get_group(i).TimeChannel)
else:
max_len = min(max_len, len(yop.get_group(i).TimeChannel))
min_time = max(min_time, min(yop.get_group(i).TimeChannel))
return max_len-1000, max(242, min_time + 2)
grlen_time = group_len(yop, 68, 140)
max_len = grlen_time[0]
min_time = grlen_time[1]
time = np.linspace(0, (max_len - 1) * 0.01, max_len)
for i in range(0,5):
signal = yop.get(signallist[i])
signal.timestamps = signal.timestamps - min_time
signal = signal.interp(time)
data_sg = signal.samples
name_sg = signal.name
inex_sg = signal.timestamps
mydata = pd.DataFrame( data =data_sg , index=index_sg, columns=name_sg)
print(df)
whl_spd_fl = signal()
我要像这样(数据框)
time whl_spd_rr whl_spd_rl whl_spd_fl whl_spd_fr
0 0 0 0 0
0.01 1 1 1 1
0.02 2 2 2 2
0.03 4 4 4 4
0.04 10 10 10 10
0.05 15 15 15 15
0.06 20 19 19 19
0.07 21 20 20 20
0.08 22 21 21 21
0.09 24 23 21 22
0.10 10 11 11 11
0.11 8 10 10 10
答案 0 :(得分:1)
自API起至少有asammdf版本5.10.3:
已删除熊猫导出选项。您应该改用to_dataframe方法。
from asammdf import MDF
mdf_obj = MDF('file.mf4')
df = mdf_obj.to_dataframe()
答案 1 :(得分:0)
yop = MDF(file_name, memory='minimum')
to_keep = ['Channl1', 'Channel2', ('CR_Bms_Soc_Pc', 102) ] # and so on
df = yop.filter(to_keep).cut(start=240, stop=2050).export('pandas', raster=0.01)
答案 2 :(得分:0)
df= mdf.filter(signallist).export(fmt='pandas')