# CSV file encoded with Windows-1252 causes garbled text when read as UTF-8

- **ID:** `data/csv-encoding-mismatch-windows-1252`
- **Domain:** data
- **Category:** encoding_error
- **Error Code:** `CSV_ENCODING_WINDOWS_1252`
- **Verification:** ai_generated
- **Fix Rate:** 95%

## Root Cause

The CSV file was saved with Windows-1252 encoding (common on legacy systems) but the reader assumes UTF-8, causing misinterpretation of bytes for characters like accented letters.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Python 3.10 | active | — | — |
| pandas 2.0.0 | active | — | — |
| Microsoft Excel 2019 | active | — | — |

## Workarounds

1. **Use Python's `chardet` library to detect encoding and then read with the correct encoding: `import chardet; with open('file.csv', 'rb') as f: result = chardet.detect(f.read()); df = pd.read_csv('file.csv', encoding=result['encoding'])`.** (95% success)
   ```
   Use Python's `chardet` library to detect encoding and then read with the correct encoding: `import chardet; with open('file.csv', 'rb') as f: result = chardet.detect(f.read()); df = pd.read_csv('file.csv', encoding=result['encoding'])`.
   ```
2. **Convert the file to UTF-8 using iconv: `iconv -f WINDOWS-1252 -t UTF-8 input.csv > output.csv`.** (90% success)
   ```
   Convert the file to UTF-8 using iconv: `iconv -f WINDOWS-1252 -t UTF-8 input.csv > output.csv`.
   ```

## Dead Ends

- **** — Adding UTF-8 BOM to the file does not fix the encoding; it only helps with byte order marking but does not convert the actual character encoding. (90% fail)
- **** — Manually replacing garbled characters one by one is error-prone and does not scale for large files. (80% fail)
