【发布时间】:2021-12-18 16:07:24
【问题描述】:
我有一个包含几列的表格,其中数字显示为对象。我想将这种格式“[0.015158]”的对象转换为浮点数“0.015158”
我的代码是:
coeff_dfethapoly['Slope (b)_d1']= pd.to_numeric(coeff_dfethapoly['Slope (b)_d1'], errors = 'coerce')
此代码不起作用,结果为“NaN”。
【问题讨论】:
-
您可能希望包含minimal reproducible example 以帮助人们重现您的问题。我怀疑解决方案很简单,但我不能确定,因为我无法用你不完整的代码重现问题。一些想法:(1)明确
pd是什么; (2) 添加print语句,显示相关对象的值。