python
runtime_error
ai_generated
true
ValueError: 没有可连接的对象
ValueError: No objects to concatenate
ID: python/pandas-concat-empty-frames
80%修复率
88%置信度
0证据数
2024-03-30首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
pd.concat() 收到空列表,通常因为过滤或列表推导未产生任何 DataFrame。
English
pd.concat() received an empty list, typically because a filter or list comprehension produced no DataFrames.
解决方案
-
95% 成功率
if frames: result = pd.concat(frames, ignore_index=True) else: result = pd.DataFrame()
-
90% 成功率
result = pd.concat(frames or [pd.DataFrame()], ignore_index=True)
无效尝试
常见但无效的做法:
-
90% 失败
ignore_index doesn't help with empty list
-
75% 失败
Downstream code then fails on None