python runtime_error ai_generated true

ValueError: 没有可连接的对象

ValueError: No objects to concatenate

ID: python/pandas-concat-empty-frames

其他格式: JSON · Markdown 中文 · English
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.

generic

解决方案

  1. 95% 成功率
    if frames: result = pd.concat(frames, ignore_index=True) else: result = pd.DataFrame()
  2. 90% 成功率
    result = pd.concat(frames or [pd.DataFrame()], ignore_index=True)

无效尝试

常见但无效的做法:

  1. 90% 失败

    ignore_index doesn't help with empty list

  2. 75% 失败

    Downstream code then fails on None