CSV’s entire appeal is simplicity — plain text, comma-separated values, readable in any text editor or spreadsheet tool without special software. That same simplicity is also where most CSV-related bugs come from.
The Format, and Where It Breaks
A CSV file is rows of data with values separated by commas, one row per line. The complications start when your data itself contains a comma — a properly formatted CSV wraps that field in quotes (“Smith, John”), but not every tool generates or parses this correctly, which is the source of most “why did my CSV import wrong” problems. Similarly, values containing quote characters or line breaks need careful escaping that not all CSV writers handle consistently.
Working With CSV in Python
import csv
# Reading
with open('data.csv', newline='', encoding='utf-8') as f:
reader = csv.DictReader(f)
for row in reader:
print(row['name'], row['email'])
# Writing
with open('output.csv', 'w', newline='', encoding='utf-8') as f:
writer = csv.DictWriter(f, fieldnames=['name', 'email'])
writer.writeheader()
writer.writerow({'name': 'Jane Doe', 'email': 'jane@example.com'})
Using Python’s built-in csv module (rather than manually splitting on commas) handles the quoting and escaping edge cases correctly — a common beginner mistake is writing a naive line.split(',') parser, which breaks the moment a field contains a comma.
For Larger Datasets: Pandas
import pandas as pd
df = pd.read_csv('data.csv')
df['total'] = df['price'] * df['quantity']
df.to_csv('output.csv', index=False)
Pandas’ read_csv/to_csv handle the same edge cases as Python’s csv module, with the added benefit of straightforward data manipulation (filtering, aggregation, calculated columns) once loaded — the practical default for anything beyond simple read/write.
Common CSV Pitfalls
- Encoding mismatches — a CSV saved in one encoding (Windows-1252) opened assuming another (UTF-8) produces garbled special characters; explicitly specify encoding rather than assuming a default.
- Excel’s auto-formatting — opening a CSV directly in Excel can silently convert values (stripping leading zeros from IDs, converting date-like strings to actual dates), corrupting data without any error message.
- Inconsistent delimiters — some regions default to semicolon-separated values due to comma being the decimal separator locally; verify the actual delimiter rather than assuming comma universally.
Frequently Asked Questions
Should I use CSV or JSON for a new data export feature?
CSV is more broadly compatible with spreadsheet tools and simpler for flat, tabular data; JSON handles nested/hierarchical data far better — choose based on your data’s actual structure and your audience’s expected tooling.
Conclusion
CSV’s simplicity is genuinely useful for tabular data exchange, but that simplicity hides real edge cases around quoting, encoding, and delimiter variation. Use a proper CSV library (Python’s csv module or pandas) rather than naive string splitting, and watch for Excel’s silent auto-formatting when opening CSVs manually.
📑 About the author: I also build Digital Bizz Card — hosted digital business cards you can share with a QR code, no app required.


