You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Pandas空间数据框加载失败:无法将非有限值转换为整数

问题诊断与解决方案

可能原因及对应解决办法:

  • 库版本更新导致逻辑变更
    近期ArcGIS API for Python(或依赖的pandas库)的版本更新,可能调整了空间DataFrame的类型推断规则——之前能兼容空值的整型字段,现在会因为空值(以浮点数NaN形式存在)触发类型转换错误。
    解决:回退到之前正常运行的版本,执行命令:

    pip install arcgis==[你2022年8月使用的版本号]
    
  • 显式指定字段数据类型
    放弃自动类型推断,手动指定存在空值的整型字段为浮点型,避免转换冲突:
    处理在线图层:

    # 替换成你实际有问题的字段名
    dtype_map = {'target_integer_field': float}
    tagol_df = pd.DataFrame.spatial.from_layer(fLayer, dtype=dtype_map)
    

    处理本地要素类:

    dtype_map = {'target_integer_field': float}
    gdb_df = pd.DataFrame.spatial.from_featureclass(lyrPath, dtype=dtype_map)
    
  • 数据源字段定义被修改
    检查托管图层或本地GDB的字段类型——可能有人修改了字段定义(比如从浮点型改成整型),但数据里仍遗留空值,导致转换失败。可以通过ArcGIS Pro或ArcCatalog查看字段属性,确认是否和之前一致。

  • 预处理空值(谨慎使用)
    如果业务允许,先将空值替换为整型可接受的默认值(比如0)再转换,注意这种方法会丢失空值信息:

    # 以在线图层为例,替换指定字段的空值
    null_features = fLayer.query(where='target_integer_field IS NULL').features
    for feat in null_features:
        feat.attributes['target_integer_field'] = 0
    fLayer.edit_features(updates=null_features)
    # 再创建DataFrame
    tagol_df = pd.DataFrame.spatial.from_layer(fLayer)
    

内容的提问来源于stack exchange,提问作者Sarah Strack

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 06:05:21