{
  "id": "python/pandas-keyerror-column",
  "signature": "KeyError: \"['column_name'] not in index\"",
  "signature_zh": "KeyError：\"['column_name'] not in index\"",
  "regex": "KeyError:\\ \"\\['column_name'\\]\\ not\\ in\\ index\"",
  "domain": "python",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "Referenced column does not exist in the DataFrame, often due to whitespace, case, or rename operations.",
  "root_cause_type": "generic",
  "root_cause_zh": "引用的列在 DataFrame 中不存在，常因空白、大小写或重命名操作导致。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Still raises KeyError if column truly missing",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Silently produces empty results downstream",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "print(df.columns.tolist()) and normalize with df.columns = df.columns.str.strip()",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "cols = [c for c in wanted if c in df.columns]; df[cols]",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.89,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-05-14",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}