# KeyError: "['column_name'] 不在索引中"

- **ID:** `python/pandas-keyerror-column-not-found`
- **领域:** python
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

列名不匹配，通常由于前后空格、大小写差异，或读取 CSV 时 header 偏移导致期望的列实际是行值。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.x | active | — | — |

## 解决方案

1. **** (90% 成功率)
   ```
   df.columns = df.columns.str.strip(); print(df.columns.tolist())
   ```
2. **** (85% 成功率)
   ```
   pd.read_csv(path, skiprows=1) or header=0 to align headers
   ```

## 无效尝试

- **** — Same KeyError, column still absent (90% 失败率)
- **** — Returns None silently, downstream operations then crash (70% 失败率)
