0.6.7 CSV Files

CSV Is a Simple Way to Store Structured Data

A CSV file stores tabular data as plain text.

CSV commonly stands for comma-separated values.

Instead of displaying data in spreadsheet cells, a CSV file represents rows and fields using text.

For example:

Activity diagram showing line row, then comma-separated value field value.
LineRow.
  • New
  • Changed
  • Removed

That makes CSV easy for many systems to create, exchange, and read.

The Header Gives Meaning to the Fields

The first line:

Activity diagram showing Title Northern Lights, then Artist Example Band, then Genre Rock, then Year 2024.
TitleNorthernLights.
  • New
  • Changed
  • Removed

Without the header, the values would be much harder to interpret.

Field Order Matters

Consider:

Activity diagram showing system A, then CSV file, then system B.
SystemA.
  • New
  • Changed
  • Removed

For example:

  • a spreadsheet can import a CSV;
  • a program can load CSV data;
  • another system can export records as CSV.

The file acts as a structured handoff.

A CSV File Still Needs Good Data Structure

CSV does not automatically make data clean.

A file can still contain:

  • inconsistent spelling;
  • duplicate records;
  • missing identifiers;
  • values in the wrong fields;
  • inconsistent capitalization.

CSV provides a format.

The quality and usefulness of the data still depend on how the records and fields are organized.

The next Learning Activity gives those parts more precise names.