我正在处理的数据框的一列包含具有以下值的字符串:
df['Records Lost'][0]
'1,37e+09'
这是一个字符串:
type(df['Records Lost'][0])
str
我尝试将其转换为浮点型,但出现此错误:
float(df['Records Lost'][0])
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-36-88765fb941e9> in <module>()
----> 1 float(df['Records Lost'][0])
ValueError: could not convert string to float: '1,37e+09'
根据@Jezreal尝试pd.to_numeric
pd.to_numeric(df['Records Lost'][0])
ValueError: Unable to parse string "1,37e+09" at position 0
pd.to_numeric([x.replace(',','.') for x in df['Records Lost'][0]])
ValueError: Unable to parse string "." at position 1
如何将此字符串转换为float / int?