我有一个看起来像这样的字符串:
a = "'92.345'\r\n\r\n"
a.strip()
当我尝试使用np.float(a)
或just将其转换为float时float(a)
,我得到
*** Value error: could not convert string to float: '92.345'
如何将其干净地转换为浮点数?
你需要剥去你的字符串,删除空格和一个报价'
:
>>> float(a.strip().strip("'"))
92.345
或如@Martijn Pieters在评论中所说,您可以使用usea.strip("\r\n\t '")
将其减少为一个脱衣舞。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句