将字符串转换为浮点数 - python

anl*_*a01 3 python string null type-conversion pandas

考虑到它包含 N/A 值,如何将一个字符串列转换为浮点数?我尝试使用 to_numeric 函数,但收到错误:“无法解析位置处的字符串“N/A”。

anl*_*a01 5

在我的例子中有效的解决方案是将参数errors='coerce'添加到to_numeric函数中。

df["mycolumn"] = pd.to_numeric(df["mycolumn"], errors='coerce', downcast="float")