# CSV parsing error: quote character mismatch — expected '"' but found ''

- **ID:** `data/csv-quote-escape-mismatch`
- **Domain:** data
- **Category:** encoding_error
- **Error Code:** `CSVParseException`
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

CSV file uses single quotes for quoting fields but parser expects double quotes, or vice versa, often due to locale or export settings.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| python 3.12 | active | — | — |
| pandas 2.2.0 | active | — | — |
| apache-commons-csv 1.10.0 | active | — | — |

## Workarounds

1. **Specify the correct quote character in pandas: `pd.read_csv('file.csv', quotechar="'")` if the file uses single quotes.** (90% success)
   ```
   Specify the correct quote character in pandas: `pd.read_csv('file.csv', quotechar="'")` if the file uses single quotes.
   ```
2. **Use the `escapechar` parameter if quotes are escaped with backslash: `pd.read_csv('file.csv', escapechar='\\')`.** (85% success)
   ```
   Use the `escapechar` parameter if quotes are escaped with backslash: `pd.read_csv('file.csv', escapechar='\\')`.
   ```
3. **Preprocess the file with a Python script to normalize quotes: `import csv; with open('input.csv', 'r') as f, open('output.csv', 'w', newline='') as out: reader = csv.reader(f, quotechar="'"); writer = csv.writer(out, quotechar='"'); writer.writerows(reader)`** (95% success)
   ```
   Preprocess the file with a Python script to normalize quotes: `import csv; with open('input.csv', 'r') as f, open('output.csv', 'w', newline='') as out: reader = csv.reader(f, quotechar="'"); writer = csv.writer(out, quotechar='"'); writer.writerows(reader)`
   ```

## Dead Ends

- **Manually replacing all single quotes with double quotes in the CSV file using sed** — This can corrupt data if single quotes are part of the field content (e.g., names like O'Brien). (60% fail)
- **Ignoring the error and proceeding with partially parsed data** — Results in misaligned columns and corrupt data; downstream processes will fail or produce wrong results. (95% fail)
- **Specifying quote character in parser but using the wrong escape character** — If the escape character is also wrong (e.g., backslash vs doubling), parsing will still fail on embedded quotes. (70% fail)
