The ghost in every CSV export

Open a comma-separated file in pandas and you may meet a column called Unnamed: 0. It is not a bug. It is a ghost — the residue of a header line that may or may not be there, in a format that has never quite had a rule about it. The ghost is older than the library, older than the web, and older than the document that was supposed to lay it to rest.

That document is RFC 4180, “Common Format and MIME Type for CSV Files,” published in October 2005 and filed, with admirable honesty, as Informational. It did not invent the comma-separated file. It did something rarer: it admitted it was only taking notes. The format section, in the RFC’s own words, “documents the format that seems to be followed by most implementations.”

That single word — seems — is the whole story of CSV, and the reason text/csv has outlasted almost every format designed to replace it.

The short version

  • RFC 4180, October 2005, Informational, registers the media type text/csv and “documents the format that seems to be followed by most implementations.”
  • Its premise is an admission: “there is no formal specification in existence, which allows for a wide variety of interpretations of CSV files.”
  • What it actually fixes is a short, concrete list: CRLF record separators, no trailing comma, “Spaces are considered part of a field and should not be ignored,” quoting for commas, line breaks and quotes, and a doubled quote inside a quoted field.
  • What it leaves unresolved — encoding, delimiter choice in comma-decimal locales, and how a reader knows whether the first row is data or labels — is most of what still goes wrong.

A format that spread without an owner

Spreadsheets were writing comma-separated files long before anyone registered a media type for them. Every tool that read one made its own decisions about the hard cases: what a comma inside a value means, whether a leading space counts, whether the first line is data or labels, and what a lone quotation mark is supposed to be.

The result was the most widely produced data format on earth and one of the least agreed. There was no owner to appeal to, no version number to cite, no committee to blame. There was only behaviour, replicated by habit and by export button.

By the early 2000s the format had outrun every attempt to specify it. Vendor documents existed; none of them won. What was missing was not a design. It was a record.

The word “seems” in a specification

A standards document normally tells you what a format is. RFC 4180 tells you what it appears to be. Y. Shafranovich’s text opens with the confession — “While there are various specifications and implementations for the CSV format... there is no formal specification in existence, which allows for a wide variety of interpretations of CSV files” — and then does the only honest thing available: it describes the majority.

Read the boilerplate and the modesty gets louder. Informational RFCs of that era carry the line “It does not specify an Internet standard of any kind.” The world’s most exported data format is defined by a document that explicitly declined to define anything.

Even the prose wobbles. The rule introducing the header line reads “There maybe an optional header line” — a typo, in the standard, in the very sentence that creates the ambiguity half the world’s data pipelines still trip over. Nobody fixed it, because nobody had to. The parsers had already voted.

The rules RFC 4180 did settle

The useful part of RFC 4180 is short and specific, and each item closed an argument that had been quietly corrupting files for years:

  • Records sit on separate lines, delimited by CRLF; the last record “may or may not have an ending line break.”
  • Fields are separated by commas, and “Each line should contain the same number of fields throughout the file.”
  • “The last field in the record must not be followed by a comma.”
  • “Fields containing line breaks (CRLF), double quotes, and commas should be enclosed in double-quotes.”
  • Inside a quoted field, “a double quote appearing inside a field must be escaped by preceding it with another double quote.”

Then comes the clause that has saved more data than any other: “Spaces are considered part of a field and should not be ignored.” It reads like housekeeping. It is not. Trimming whitespace is exactly what a helpful reader does, and a helpful reader is how a part number quietly becomes a different part number.

What RFC 4180 left alone — and said so

The document is candid about its own gaps. It notes that “some programs, such as Microsoft Excel, do not use double quotes at all,” which is a polite way of saying the most popular CSV producer on earth plays by different rules. The media type registration carries optional charset and header parameters — the second with values present and absent — which means the reader still has to be told, or guess.

Everything else stayed outside the description. Encoding got a parameter and no mandate. Delimiter choice was left to locales that use the comma as a decimal separator, which is why much of Europe exports semicolon-separated files and Excel prepends a sep=; line that no specification ever authorised. Leading zeros in zip codes, phone numbers rendered in scientific notation, the SYLK warning that appears when a file’s first cell happens to read ID, and the formula-injection problem that turns a field beginning with = into an executable cell — all of it lives in the space RFC 4180 described but did not govern.

Why describing a de facto format still counts

A written description gives an argument something to point at. Before October 2005, two tools that disagreed could each claim to be right. Afterwards there was a document, however hedged, and a name for the data on the wire.

This is running code in its purest form, and it inverts the usual order of standards work. The parsers voted first; the document recorded the vote. Lu Heng’s Note on heng.lu puts the general case in one line: “Reality does not need to be invented. It only needs to be described.” RFC 4180 is that sentence with a MIME registration attached.

It is also why the document worked. A specification written before the practice would have been a proposal, and proposals get ignored. A specification written after the practice was a mirror, and mirrors are hard to argue with.

The cost of codifying the median

What RFC 4180 anoints is not the best behaviour but the commonest. Every quirk it recorded became slightly more permanent the moment it was written down, and the tools that did something better inherited a compatibility burden they never asked for.

The genre is worth naming: some standards are designs, and some are descriptions that quietly become designs by being the only written copy. CSV is the second kind, and it has proved remarkably hard to displace. RFC 7111 later gave text/csv a fragment identifier syntax for pointing at rows and columns. The W3C’s CSV on the Web work tried to bolt a schema onto the format in 2015. Neither changed what your accounting package exports on a Friday afternoon.

Two decades on, the description still runs the world’s data plumbing — unowned, unversioned, and defined by a document that never claimed to define anything. CSV never got a constitution. It got minutes, and the minutes turned out to be enough.