Knowledgebase

Working With CSV and Spreadsheet Data Print

  • python, guide, howto, solution, zillionkinghost, hosting, support
  • 0

Tabular files.

WHAT CSV IS

Plain text, one record per line, values separated by commas.

The most common interchange format for tabular data.

WHY NOT TO PARSE IT YOURSELF

Values containing commas, quotes or line breaks break naive splitting.

Use the library built for it.

WHAT IT HANDLES

Quoting Embedded separators Headers

READING AS RECORDS

The library can return each row as a dictionary keyed by the header.

Far clearer than working with positions.

WHAT TO CHECK

The encoding, which is a frequent source of mangled characters Whether a header row exists Whether the separator is genuinely a comma

THAT LAST POINT

Some systems export with semicolons or tabs.

WHAT TO BE CAREFUL WITH

Values that look like numbers but should stay as text, such as reference codes with leading zeros Dates, which arrive as text and need converting

FOR SPREADSHEET FILES

Libraries exist for reading them directly.

WHEN TO PREFER CSV

Whenever possible. Simpler and more reliable.

WHAT TO VALIDATE

That the row count matches expectations.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot