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
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'.
解决方案
-
95% 成功率
pd.to_numeric(s, errors='coerce').fillna(0)
-
85% 成功率
s.replace({'N/A': None, '-': None}).astype('Float64')
无效尝试
常见但无效的做法:
-
80% 失败
Other tokens ('-', 'null') still fail
-
70% 失败
Keeps object dtype; downstream numeric ops fail