python data_error ai_generated true

ValueError:无法解析位置 3 处的字符串 "N/A"

ValueError: Unable to parse string "N/A" at position 3

ID: python/pandas-to-numeric-nonnumeric

其他格式: JSON · Markdown 中文 · English
80%修复率
90%置信度
0证据数
2024-10-28首次发现

版本兼容性

版本状态引入弃用备注
3.x active — — —

根因分析

pd.to_numeric 遇到非数值标记而未设置 errors='coerce'。

English

pd.to_numeric hits non-numeric tokens without errors='coerce'.

generic

解决方案

  1. 95% 成功率
    pd.to_numeric(s, errors='coerce').fillna(0)
  2. 85% 成功率
    s.replace({'N/A': None, '-': None}).astype('Float64')

无效尝试

常见但无效的做法:

  1. 80% 失败

    Other tokens ('-', 'null') still fail

  2. 70% 失败

    Keeps object dtype; downstream numeric ops fail