900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > ValueError: could not convert string to float:

ValueError: could not convert string to float:

时间:2024-06-25 16:51:22

相关推荐

ValueError: could not convert string to float:

用python读取excel的列数据时报错ValueError: could not convert string to float: ,意思是有取到一个空字符,无法转换,这才想起来我的excel里确实有不少空值

解决方案一:用try except

try:sheet1_rowvalue[4] = float(sheet1_rowvalue[4])except ValueError:sheet1_rowvalue[4] = ''

解决方案二:用if

if( sheet1_rowvalue[4]):sheet1_rowvalue[4] = int(sheet1_rowvalue[4])

就把空值过滤掉了,如果是有‘?’等其他字符,则只能用方案一解决

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。