Build an ETL process for CSV data

A practical review of CSV and TSV ETL: what extraction, conversion and loading change in your data, when the result stays usable, and when plain text is the safer choice.

An ETL process for CSV data extracts records from delimited files, transforms them into a consistent shape, and loads them somewhere useful, such as a database, a spreadsheet or another delimited file. The format looks simple, which is why it is easy to damage. This review explains what each stage actually changes, which changes alter meaning rather than appearance, and how to tell whether the output will still work wherever it ends up.

Is a CSV ETL workflow suitable for your use?

A CSV ETL process is suitable when you need repeatable, inspectable movement of tabular records between systems that do not share a native connection. Its main benefit is transparency. The input and output are plain text, so you can open them, diff them and reason about every field.

The decisive tradeoff is that CSV carries no reliable metadata. It does not record the encoding, the data type of a column, or a single agreed rule for quoting. Every ETL step has to make those decisions explicitly. If it doesn't, the data can quietly change meaning, for example when an identifier with leading zeros becomes a number or a date is reinterpreted in another regional format.

Keep the data as untouched plain text, with no type conversion or reshaping, when the destination is an archive, an audit trail, or a handoff to someone who will apply their own rules. In those cases, the most faithful output is often the original file plus a short description of its delimiter, encoding and header row.

What each stage actually changes

It helps to separate changes to the stored characters from changes in how a program displays or interprets them. Only the first kind is written into the file, but the second kind becomes the first kind as soon as someone re-saves the file.

Stage | Typical change | Stored or presentational
Extract | Decoding bytes to text using a chosen encoding; splitting rows and fields using delimiter and quote rules | Stored, if the decoded text is written back out
Transform: delimiter conversion | Commas replaced by tabs (CSV to TSV) and quoting rules rewritten | Stored
Transform: normalization | Trimming whitespace, unifying line endings, Unicode normalization, case folding | Stored
Transform: typing | Parsing strings into numbers, dates or booleans | Stored in the destination; may lose original formatting
Load into a spreadsheet | Auto-detected types, hidden leading zeros, scientific notation for long numbers | Presentational until re-saved, then stored
Load into a database | Values coerced to column types; rejected or truncated rows | Stored

Delimiters and quoting

The widely cited CSV convention (RFC 4180) wraps a field in double quotes when it contains a comma, a quote or a line break, and represents a literal quote by doubling it. "TSV" is less settled. Some definitions forbid tabs and line breaks inside fields and use no quoting at all. Many libraries, however, apply CSV-style quoting with a tab delimiter. A conversion is only correct relative to the convention the destination expects.

Here is an illustrative CSV input. The second field of the first data row contains a comma, and the third contains quotes.

id,name,note
1,"Smith, Jane","Said ""hello"""
2,Lee,

Under a strict no-quoting TSV convention, the same data becomes the following. The comma no longer needs protection, and the quotes are literal characters. The second data row keeps its trailing empty field as a trailing tab.

id	name	note
1	Smith, Jane	Said "hello"
2	Lee	

The minimal Python script below does not produce exactly that output. With its default minimal quoting, Python's csv writer still quotes any field that contains a quote character. The note field would therefore be written as "Said ""hello""" even with a tab delimiter. Neither result is wrong in general, but only one will match a given importer. Set the quoting behavior on purpose and check a sample row against the destination's documented rules.

import csv

with open("in.csv", newline="", encoding="utf-8-sig") as src, \
     open("out.tsv", "w", newline="", encoding="utf-8") as dst:
    reader = csv.reader(src)
    writer = csv.writer(dst, delimiter="\t", lineterminator="\n")
    for row in reader:
        writer.writerow(row)

Two details in the script matter. Opening files with newline="" lets the csv module handle line breaks inside quoted fields correctly. Reading with the utf-8-sig encoding removes a leading byte order mark if one is present, so the first header name doesn't silently start with an invisible character.

Encoding and Unicode normalization

Decoding a file with the wrong encoding replaces accented letters and symbols with garbled sequences. Once those sequences are written back out, the original text cannot always be recovered. Confirm the source encoding before transforming anything, and write the output in a single declared encoding.

Text that looks identical can be stored differently. An accented letter may be one precomposed code point or a base letter followed by a combining mark. Emoji can be sequences of several code points joined together. If an ETL step deduplicates, joins on a text key, or truncates fields to a length, apply one Unicode normalization form first. Measure length in user-perceived characters rather than code points or bytes, or a cut can land in the middle of a character.

Clarifying "reverse", "mirror" and "font" in a CSV context

In tabular ETL, "reverse" usually means reversing row order or swapping rows and columns (transposing or unpivoting). Neither changes the characters inside a field. Reversing the characters within a field is rarely meaningful for data, and if it is done naively by code point it breaks combining marks and multi-code-point emoji.

Decorative "fonts" pasted from Unicode styling tools are not fonts. They are separate mathematical or symbol code points. A name stored that way will not match the plain-letter version in a join, a search or a lookup, so a cleansing step should flag or reject such characters if consistent matching matters.

Right-to-left text, such as Arabic or Hebrew, is stored in logical order. Some editors may display a field that mixes directions in an order that looks reversed. That is a presentation effect, and the stored text should not be "corrected" by reordering characters.

Will the output stay readable and usable after copying or sharing?

Usability depends on the destination, and behavior varies between applications and versions. A clean load into one program is not evidence that another program will read the file the same way. Test against each named destination with a sample that includes the awkward cases.

  • Fields containing the delimiter, quotes and line breaks
  • Identifiers with leading zeros and very long numeric strings
  • Dates in an ambiguous day/month order
  • Non-ASCII text, combining marks, emoji and right-to-left text
  • Empty fields, including a trailing empty field at the end of a row
  • Cells beginning with =, +, - or @

That last case matters for anything that will be opened in a spreadsheet. Some spreadsheet programs evaluate cell content that starts with those characters as a formula, a risk known as CSV or formula injection. If untrusted data may be shared that way, decide in the transform stage whether to neutralize such values and document the choice. The neutralization itself alters the stored text.

Copying and pasting is a transformation of its own. When delimited text is pasted into a spreadsheet, the program decides how to split it, and that decision may depend on its settings and on whether the text uses tabs or commas. When cells are copied out of a spreadsheet, the displayed values may be copied rather than the underlying ones. Hidden leading zeros or rounded numbers can then be lost. If exact values matter, move files rather than clipboard contents.

For accessibility, raw delimited text is not a table to assistive technology. A screen reader reading a CSV file in a text editor encounters a stream of values and punctuation, with no column headers announced. Providing the data in a properly structured table, in a spreadsheet or a marked-up document with header cells, is generally more navigable. Confirm this with the specific screen reader and application your audience uses, because no scoped test results were available for this article.

Search and editing are affected too. Styled Unicode characters, inconsistent normalization and invisible characters such as byte order marks or non-breaking spaces can make values unsearchable or cause edits to fail matching. A plain-text equivalent, normalized and free of decorative characters, is needed whenever the data will be searched, matched, read by assistive technology, or imported into a system you do not control.

Recommendation

Build the ETL process in this order:

  • Make the extract rules explicit: encoding, delimiter, quote character and header handling.
  • Keep the original files unchanged.
  • Apply normalization deliberately.
  • Delay type conversion until the load step, where the destination's rules are known.
  • Validate output against each real destination using an edge-case sample.

If the data's next user needs fidelity more than convenience, deliver plain, minimally transformed text along with a description of its format.

Evidence gaps

No specific tools, performance figures or destination test results were available for this review. Statements about spreadsheet and screen reader behavior describe general, commonly documented patterns rather than verified observations of particular products. Nothing here describes the privacy or data retention practices of any online conversion tool. Check a tool's own documentation before uploading sensitive data to it.