将字符串转换为浮点数 - python
Converting string to float - python
考虑到一个字符串列包含 N/A 个值,我如何将它转换为浮点数?
我尝试使用 to_numeric 函数,但收到错误消息:“无法在位置解析字符串“N/A”。
适用于我的解决方案是将参数 errors='coerce' 添加到 to_numeric 函数。
df["mycolumn"] = pd.to_numeric(df["mycolumn"], errors='coerce', downcast="float")
考虑到一个字符串列包含 N/A 个值,我如何将它转换为浮点数? 我尝试使用 to_numeric 函数,但收到错误消息:“无法在位置解析字符串“N/A”。
适用于我的解决方案是将参数 errors='coerce' 添加到 to_numeric 函数。
df["mycolumn"] = pd.to_numeric(df["mycolumn"], errors='coerce', downcast="float")