Convert CSV to MDF
Convert CSV measurements to ASAM MDF4 or import CSV data into a SQL Server database.
Convert CSV files online
We don’t have a dedicated online converter for CSV to MDF yet, but you can convert CSV files online to these and more formats:
How to convert csv to mdf file
- Databases
- No ratings yet.
A test, automotive, or data-analysis program may require an ASAM Measurement Data Format file instead of a plain text table. A database workflow may instead require a Microsoft SQL Server database whose primary data file has the .mdf extension; these are different formats and require different conversion procedures.
What CSV contains
CSV is a plain-text tabular format: rows represent records, while commas, semicolons, or tabs separate fields. Microsoft Excel, LibreOffice Calc, Google Sheets, data loggers, laboratory instruments, database exports, and scripts commonly create CSV files.
CSV usually stores values without defining signal metadata, binary data types, channel groups, sampling rates, calibration formulas, device identity, or measurement start time. A timestamp column may be present, but a file containing only samples requires a known sample period before it can represent a timed measurement.
Which MDF do you mean?
ASAM MDF is a binary measurement-data format used for automotive testing, CAN and ECU analysis, data acquisition, and test equipment. Current files commonly use .mf4; older MDF 3 files commonly use .mdf. MDF stores channels, channel groups, timestamps, units, data types, source information, and measurement metadata, allowing compatible software to access large recordings efficiently and keep synchronized signals together.
Microsoft SQL Server MDF is a database storage file, not a measurement format. SQL Server manages the file and its associated transaction log; changing a CSV filename to .mdf cannot create a valid database. If the destination is SQL Server, import the CSV into a new or existing database and let SQL Server create the data files.
Convert CSV to ASAM MDF with Python
The open-source asammdf package gives the most control over channel names, timestamps, units, and output version. Install it with:
python -m pip install asammdf numpyPrepare a UTF-8 CSV with a header row. This example expects timestamps in seconds and numeric signal columns:
time,EngineSpeed,VehicleSpeed
0.000,800,0
0.010,805,0.2
0.020,810,0.4Save the following as csv_to_mdf.py, changing the channel names and units to match the source:
import csv
import numpy as np
from asammdf import MDF, Signal
input_file = "measurement.csv"
output_file = "measurement.mf4"
time_name = "time"
units = {"EngineSpeed": "rpm", "VehicleSpeed": "km/h"}
with open(input_file, newline="", encoding="utf-8-sig") as file:
rows = list(csv.DictReader(file))
if not rows:
raise ValueError("The CSV contains no data rows")
if time_name not in rows[0]:
raise ValueError("The CSV must contain a 'time' column")
timestamps = np.array([float(row[time_name]) for row in rows], dtype=float)
if np.any(~np.isfinite(timestamps)) or np.any(np.diff(timestamps) < 0):
raise ValueError("Timestamps must be finite and nondecreasing")
mdf = MDF(version="4.10")
for name in rows[0]:
if name == time_name:
continue
samples = np.array([float(row[name]) for row in rows], dtype=float)
mdf.append(Signal(samples=samples, timestamps=timestamps,
name=name, unit=units.get(name, "")))
mdf.save(output_file, overwrite=True)Run it with python csv_to_mdf.py. Open the resulting measurement.mf4 in an MDF reader and check channel names, units, timestamps, sample counts, missing values, and numeric ranges. The script writes floating-point channels; preserve Boolean, integer, enumerated, byte-array, or text signals with explicit type handling when the receiving application depends on those types.
Use desktop measurement software
Measurement applications from Vector, National Instruments, Dewesoft, and other test-system vendors may import CSV channels and export ASAM MDF, but support depends on the product, version, license, and installed options. The typical workflow is File → Import → CSV, configure the delimiter, decimal separator, header row, timestamp column, and units, then choose the product’s MDF or MDF4 export command. Verify in the documentation that the output is ASAM MDF, not a proprietary file with an .mdf extension.
For a repeatable or automated conversion, asammdf is usually easier to audit than a graphical import because the timestamp construction, units, missing-value policy, and output version are explicit in the script.
Import CSV into a SQL Server database
If the required file is a SQL Server .mdf, create a database in SQL Server Management Studio or SQL Server Express, then use Tasks → Import Flat File or the SQL Server Import and Export Wizard. Select the CSV, set its delimiter, text qualifier, encoding, column types, null handling, and destination table, and let SQL Server create or extend the database.
Review inferred column types before importing: identifiers with leading zeroes should be text, dates require an unambiguous format, and long numeric values may need decimal or bigint. The result is a SQL Server database whose data may reside in an .mdf file; the CSV itself has not been converted into an ASAM measurement file. Tools such as Full Convert can migrate CSV data into a SQL Server database when supported, but they do not replace SQL Server’s database-file management.
Quality and compatibility checks
- Time base: If the CSV has no timestamps, calculate them from the documented sample rate; at 100 Hz, use 0.01-second intervals. An inferred time base cannot recover unknown timing, dropped samples, pauses, or trigger events.
- Delimiter and locale: Configure comma versus semicolon separators and decimal point versus decimal comma. A wrong setting can shift fields or import numeric values as text.
- Missing readings: Decide how empty cells,
NaN, and invalid values should be represented. Replacing gaps with zero changes the measurement unless that rule is documented. - Metadata loss: CSV normally cannot provide CAN message definitions, ECU conversion formulas, acquisition-device identity, trigger information, calibration, or original synchronization details. Add required metadata after import.
- Version and extension: Use
.mf4for MDF4 unless the destination specifically requires MDF3. Renaming.csvto.mdfperforms no conversion, and an ASAM.mdffile must not be supplied to SQL Server. - Online services: General converters rarely support standards-compliant ASAM MDF or SQL Server MDF creation. Do not upload vehicle, laboratory, or proprietary data unless a service explicitly documents the required MDF type, output validation, retention, and deletion policies; validate any downloaded file with the target application.
CSV vs MDF: format comparison
How the CSV and MDF formats compare on the properties that matter most for this conversion.
| Property | .CSV Comma-Separated Values | .MDF Media Descriptor File |
|---|---|---|
| Open standard | Yes | No |
| Compression | Uncompressed | Both |
| Typical file size | Small | Large |
| Opens in a web browser | Yes, natively | No |
| Further editing | Easy | Not directly editable |
| Metadata support | Basic | Basic |
| Plain-text readable | Yes | No |
| Best used for | Data exchange | Long-term archiving |
| Introduced | — | 2000 |
| Developer | — | Alcohol Soft |
| MIME type | text/csv | — |