I have a dataset of mf4 and I want to convert it into CSV in python. I have read the data from mf4 and convert it into csv (as given below) but I am getting an error, as I am new to python, so unable to find an appropriate method to convert.
from asammdf import MDF
import pandas as pd
efficient = MDF('./Data.mf4')
df = efficient.to_csv()
df.append(efficient)
mdf.save('output.csv')
I am getting this error:
MdfException: "Data.mf4" is not a valid ASAM MDF file: magic header is b'timestam'
Kindly suggest. Thank you!
You already have mf4 file. Is this file converted from an mdf file? If it is as I thought, you should use the mdf file to convert it into a CSV file. Here it is anyway and hopefully you or someone else can come up with a better method.
import mdfreader
import os
extension = [".mdf"]
for root, dirs, files in os.walk(input_path):
for file in files:
ext = os.path.splitext(file)[-1].lower()
f_name = os.path.splitext(file)[0]
if ext in extension:
yop=mdfreader.Mdf(os.path.join(root, file))
yop=mdfreader.Mdf(os.path.join(root, file), channel_list=['channel1', 'channel2'], convert_after_read=False)
yop=mdfreader.Mdf(os.path.join(root, file), compression=True)
yop=mdfreader.Mdf(os.path.join(root, file), no_data_loading=True)
yop=mdfreader.Mdf(os.path.join(root, file), metadata=0)
yop.get_channel_name4('channelName', 'source path or name')
yop.get_channel('channelName')
yop.get_channel_data('channelName')
yop.MDFVersionNumber
info=mdfreader.MdfInfo()
info.list_channels('NameOfFile')
info.read_info('NameOfFile')
yop.info
yop.keys()
yop.masterChannelList
yop.plot(['channel1',['channel2','channel3']])
yop.resample(0.1)
yop.resample(master_channel='master3')
yop.cut(begin=10, end=15)
yop.export_to_csv(sampling=0.01)
yop.export_to_NetCDF()
yop.export_to_hdf5()
yop.export_to_matlab()
yop.export_to_xlsx()
yop.export_to_parquet()
yop.return_pandas_dataframe('master_channel_name')
yop.convert_to_pandas()
yop.keep_channels({'channel1','channel2','channel3'})
yop2=mdfreader.Mdf('NameOfFile_2')
yop.merge_mdf(yop2)
yop.write('NewNameOfFile')
yop.write4('NameOfFile', compression=True)
yop.write3()
yop.attachments
I used lib mdfreader to do this. You can refer below link for more detail.
Thanks for your feedback. I got it your issue, you can try:
pip install https://github.com/danielhrisca/asammdf/archive/development.zip -I --no-deps
to install the development branch code and then
mdf = MDF('file.mf4')
mdf.export('csv', 'export.csv', single_time_base=True, raster=0.1)
About your case (use anaconda). Please try:
conda install https://github.com/danielhrisca/asammdf/archive/development.zip -I --no-deps
Lib mdfreader. In you want to install it.
conda install mdfreader