# FutureWarning: observed=False 的默认值已被弃用，未来版本将改为 True。

- **ID:** `python/pandas-groupby-observed-warning`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

对 Categorical 列执行 groupby 且 observed=False（旧版 pandas 默认）会生成类别的笛卡尔积，包含空组。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   df.groupby('cat', observed=True).agg('sum')
   ```
2. **** (85% 成功率)
   ```
   pd.set_option('mode.copy_on_write', True) plus explicit observed=True
   ```

## 无效尝试

- **** — Same warning, results include empty categories (85% 失败率)
- **** — Loses categorical ordering (60% 失败率)
