{
  "id": "data/csv-encoding-mismatch-windows-1252",
  "signature": "CSV file encoded with Windows-1252 causes garbled text when read as UTF-8",
  "signature_zh": "使用Windows-1252编码的CSV文件在按UTF-8读取时导致乱码",
  "regex": "CSV file encoded with Windows-1252 causes garbled text",
  "domain": "data",
  "category": "encoding_error",
  "subcategory": null,
  "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.",
  "root_cause_type": "generic",
  "root_cause_zh": "CSV文件使用Windows-1252编码保存（在旧系统中常见），但读取器假定为UTF-8，导致对重音字母等字符的字节错误解释。",
  "versions": [
    {
      "version": "Python 3.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "pandas 2.0.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Microsoft Excel 2019",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "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.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Manually replacing garbled characters one by one is error-prone and does not scale for large files.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "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'])`.",
      "success_rate": 0.95,
      "how": "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'])`.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Convert the file to UTF-8 using iconv: `iconv -f WINDOWS-1252 -t UTF-8 input.csv > output.csv`.",
      "success_rate": 0.9,
      "how": "Convert the file to UTF-8 using iconv: `iconv -f WINDOWS-1252 -t UTF-8 input.csv > output.csv`.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "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'])`.",
    "Convert the file to UTF-8 using iconv: `iconv -f WINDOWS-1252 -t UTF-8 input.csv > output.csv`."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.python.org/3/library/codecs.html#standard-encodings",
  "official_doc_section": null,
  "error_code": "CSV_ENCODING_WINDOWS_1252",
  "verification_tier": "ai_generated",
  "confidence": 0.9,
  "fix_success_rate": 0.95,
  "resolvable": "true",
  "first_seen": "2023-05-10",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}